Last active
September 21, 2022 19:38
-
-
Save MLKrisJohnson/9064a71c1db46e7db0510e2652ad3316 to your computer and use it in GitHub Desktop.
Example of configuring the Python logging module with a custom format
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 | |
def configure_logging(level=logging.DEBUG): | |
"""Configure the logging module. | |
""" | |
logging.basicConfig( | |
format="%(asctime)s.%(msecs)03d %(levelname)-7s %(message)s", | |
datefmt="%Y-%m-%d %H:%M:%S", | |
level=level) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If using this in a Jupyter notebook, add
stream=sys.stderr
to thebasicConfig
arguments to get log messages to appear in the notebook.