Last active
August 12, 2020 18:22
-
-
Save talarczykco/ae5079b5e0d389c6ec4c615279b6d158 to your computer and use it in GitHub Desktop.
Setup 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
# Created this after googling for: | |
# - python logging replace handler | |
# - python logging basicconfig not working | |
# - python logging getlogger | |
def get_logger(level='DEBUG'): | |
loghandler = logging.StreamHandler() | |
logfmt = logging.Formatter(fmt='%(asctime)s:%(name)s:%(levelname)s:%(message)s', | |
datefmt='%Y-%m-%d %H:%M:%S') | |
logger = logging.getLogger() # get root logger, not __name__ | |
loghandler.setFormatter(logfmt) | |
logger.handlers = [loghandler] | |
logger.setLevel(os.environ.get('LOG_LEVEL', level)) | |
return logger |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment