-
-
Save karma-git/e711bf8918fff93a173e3ef33c530b79 to your computer and use it in GitHub Desktop.
Honestly, I hate python logging
This file contains 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 | |
# ref: https://realpython.com/python-logging/ | |
# custom logger | |
logger = logging.getLogger(__name__) | |
# handler | |
c_handler = logging.StreamHandler() | |
# set handler and logger level | |
# CRITICAL 50 | |
# ERROR 40 | |
# WARNING 30 | |
# INFO 20 | |
# DEBUG 10 | |
c_handler.setLevel(logging.DEBUG) | |
logger.setLevel(logging.DEBUG) | |
# create formatter and assign to handler | |
c_format = logging.Formatter( | |
"%(asctime)s - %(levelname)s - %(message)s", datefmt="%d-%b-%y %H:%M:%S" | |
) | |
c_handler.setFormatter(c_format) | |
# add handler to logger | |
logger.addHandler(c_handler) | |
var = "Hello there" | |
logger.debug(f"This is a debug message - {var}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment