Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

logging date format with milliseconds and timezone

189 views
Skip to first unread message

Skip Montanaro

unread,
May 17, 2018, 3:55:12 PM5/17/18
to
It seems that the logging.Formatter class uses two formats by default to
format a time, default_time_format (%Y-%m-%d %H:%M:%S) and
default_msec_format (%s,%03d). The former is a format string for
time.strftime (and thus can't represent fractions of a second). The latter
accomplishes that, but expanding %s with the output of (I believe)
time.strftime and %03d with the milliseconds in the current time. Users can
pass a datefmt arg to logging.basicConfig, or override the aforementioned
default_*_format attributes. Is there some way to format the timestamp with
both fractions of a second and timezone in a way similar to
datetime.strftime? In particular, I'd be happy with this format:
%Y-%m-%dT%H:%M:%S.%f%z. Maybe there is some magic flag to tell the system
I'm want to use datetime.strftime instead of time.strftime?

Thx,

Skip
0 new messages