Skip to content

Instantly share code, notes, and snippets.

@MLKrisJohnson
Last active September 21, 2022 19:38
Show Gist options
  • Save MLKrisJohnson/9064a71c1db46e7db0510e2652ad3316 to your computer and use it in GitHub Desktop.
Save MLKrisJohnson/9064a71c1db46e7db0510e2652ad3316 to your computer and use it in GitHub Desktop.
Example of configuring the Python logging module with a custom format
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)
@MLKrisJohnson
Copy link
Author

If using this in a Jupyter notebook, add stream=sys.stderr to the basicConfig arguments to get log messages to appear in the notebook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment