Last active
March 8, 2023 23:37
-
-
Save saintsGrad15/45da9626f634870835260640cf59cbce to your computer and use it in GitHub Desktop.
The very most basic logging setup for Python
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 | |
| import sys | |
| # Use this format for more verbosity | |
| LOGGING_FORMAT = "%(asctime)s - %(name)s - %(levelname)s - %(message)s" | |
| logger = logging.getLogger() | |
| logger.setLevel(logging.DEBUG) | |
| handler = logging.StreamHandler(stream=sys.stdout) | |
| handler.setFormatter(logging.Formatter(logging.BASIC_FORMAT)) | |
| # Only necessary if the same code is being run multiple times as in a notebook, for instance. | |
| if len(logger.handlers) > 0: | |
| logger.handlers = [] | |
| logger.addHandler(handler) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment