Generate RFC 3339 timestamp
zxcvbn97 opened this issue · 3 comments
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)
ANyupdate?
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..