-
Notifications
You must be signed in to change notification settings - Fork 412
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
Unable to get sub-second timestamps with custom datefmt (e.g. ISO8601) #905
Comments
Hey @huonw perhaps this is not a bug unless this is supported in the standard logging library. Regardless, I'd like to provide a better way to handle this as I kept the standard time format used by std logging. I'd appreciate any suggestions you might have on how we can make this effortless -- changing the format now will break customers, but it should be easier to support other formats and custom formats |
Yeah, maybe it's a feature request. 😅
I could imagine that What do you think? |
Waiting for last CI checks and releasing it ;-) Changed the name slightly so it's easier for newcomers to know what to search logger = Logger(
service=service_name,
datefmt="custom timestamp: milliseconds=%F microseconds=%f timezone=%z",
use_datetime_directive=True, # from use_datetime
) |
Hey @huonw this is available in 1.24.0 release - thank you so much again for helping out :) |
What were you trying to accomplish?
The structured logging is great, thank you.
We find the
timestamp
field somewhat unexpected, e.g. use of,
rather than.
(ignoring device locale), and some might want to follow ISO8601 more strictly and use theT
date/time separator:2000-01-02T03:04:05.006+07:08
. (Or even other date/time formatting standards.)Unfortunately, it seems that it's impossible to provide a custom format ala
"%Y-%m-%dT%H:%M:%S.%f%z"
that satisfies this and retain the subsecond precision because neitherdatetime.strftime
's microsecond%f
nor the custom millisecond%F
are supported due to the use oftime.struct_time
/time.strftime
Expected Behavior
It would be great to be able to get sub-second timestamp precision with a custom datefmt.
Current Behavior
Subsecond precision formatters are ignored. See output below.
Possible Solution
%F
in a customdatefmt
in addition todefault_time_format
(for instance, setself.datefmt = datefmt or default_time_format
and remove theif self.datefmt
informatTime
)datetime
rather thantime
withinformatTime
Steps to Reproduce (for bugs)
Output:
Note that the timestamp fields both come out as
"2021-12-17T08:56:31.f+1100"
with af
instead of sub-second precision.Environment
The text was updated successfully, but these errors were encountered: