Created
October 26, 2020 09:44
-
-
Save barend/7b09dfc95c68083402964ff11c54c347 to your computer and use it in GitHub Desktop.
Configure Python logging with ISO-8601 format and UTC time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from time import gmtime | |
# https://stackoverflow.com/a/7517430/49489 | |
logging.basicConfig( | |
level=logging.INFO, | |
format="%(asctime)s.%(msecs)03dZ [%(name)s] %(message)s", | |
datefmt="%Y-%m-%dT%H:%M:%S", | |
) | |
logging.Formatter.converter = gmtime |
what to change if you need EST time?
This does work only if your server time is set to UTC. It is just add Z at your local time
Actually, this last line ensures the time it uses is UTC:
logging.Formatter.converter = gmtime
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This does work only if your server time is set to UTC. It is just add Z at your local time