Created
February 9, 2018 20:12
-
-
Save William-Hill/a61bb65a575f890878900c1388e2cf14 to your computer and use it in GitHub Desktop.
Python logging setup
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
'''My preferred logging setup to log the filename, line number, function name, and time in messages''' | |
import logging | |
logger = logging.getLogger('metrics_logger') | |
logger.setLevel(logging.DEBUG) | |
# create formatter | |
formatter = logging.Formatter("%(levelname)s - %(filename)s - %(lineno)s - %(funcName)s - %(asctime)s - %(message)s", datefmt='%m/%d/%Y %I:%M:%S %p') | |
# create console handler with a higher log level | |
console_handler = logging.StreamHandler() | |
console_handler.setFormatter(formatter) | |
logger.addHandler(console_handler) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment