Skip to content

Instantly share code, notes, and snippets.

View kchoudhu's full-sized avatar
💭
General misery

Kamil Choudhury kchoudhu

💭
General misery
View GitHub Profile
@kchoudhu
kchoudhu / logging_Iso8601UTCTimeFormatter.py
Created May 19, 2019 11:54 — forked from sloanlance/logging_Iso8601UTCTimeFormatter.py
Python: A logging Formatter class giving timestamps in a more common ISO 8601 format.
class Iso8601UTCTimeFormatter(logging.Formatter):
"""
A logging Formatter class giving timestamps in a more common ISO 8601 format.
The default logging.Formatter class **claims** to give timestamps in ISO 8601 format
if it is not initialized with a different timestamp format string. However, its
format, "YYYY-MM-DD hh:mm:ss,sss", is much less common than, "YYYY-MM-DDThh:mm:ss.sss".
That is, the separator between date and time is a space instead of the letter "T"
and the separator for fractional seconds is a comma instead of a period (full stop).
While these differences may not be strictly *wrong*, it makes the formatted timestamp