Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate RFC 3339 timestamp #45

Closed
zxcvbn97 opened this issue Nov 23, 2017 · 3 comments
Closed

Generate RFC 3339 timestamp #45

zxcvbn97 opened this issue Nov 23, 2017 · 3 comments

Comments

@zxcvbn97
Copy link

Is there anyway to generate RFC 3339 timestamp, for example,2014-04-28T15:44:45.758-07:00

When I pass to coloredlogs my own datefmt and enable milliseconds, it becomes 2014-04-28T15:44:45-07:00,758 (milliseconds at the end of time zone info)

@zxcvbn97
Copy link
Author

@xolox

@zxcvbn97
Copy link
Author

ANyupdate?

@xolox
Copy link
Owner

xolox commented Apr 29, 2018

Hi @zxcvbn97 and thanks for the feedback.

Until now there was no way to do what you wanted, because this isn't possible to do using Python's logging module. The reason for this is that support for millisecond precision isn't included in date/time format strings but is instead included as the %(msecs)d format and the corresponding field on LogRecord objects.

However today I released coloredlogs 9.3 which enables flexible millisecond formatting using a "fake" %f directive. Here's how you would use it:

>>> import coloredlogs, logging
>>> coloredlogs.install(datefmt='%Y-%m-%dT%H:%M:%S.%f%z')
>>> logging.info("Testing, 1, 2, 3..")
2018-04-30T00:11:51.041+0000 peter-mbp root[4885] INFO Testing, 1, 2, 3..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants