Skip to content

Instantly share code, notes, and snippets.

@talarczykco
Last active August 12, 2020 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talarczykco/ae5079b5e0d389c6ec4c615279b6d158 to your computer and use it in GitHub Desktop.
Save talarczykco/ae5079b5e0d389c6ec4c615279b6d158 to your computer and use it in GitHub Desktop.
Setup Python logging
# 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