Skip to content

Instantly share code, notes, and snippets.

@bryaneaton
Created July 22, 2021 13:27
Show Gist options
  • Save bryaneaton/ff4e285e6e9d5014e5086daa719451ec to your computer and use it in GitHub Desktop.
Save bryaneaton/ff4e285e6e9d5014e5086daa719451ec to your computer and use it in GitHub Desktop.
Useful logging class for python!
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# standard python imports
import logging
from rich.logging import RichHandler
from rich.traceback import install
import os
install()
def create_logger():
"""Create a logger for use in all cases."""
LOGLEVEL = os.environ.get('LOGLEVEL', 'INFO').upper()
rich_handler = RichHandler(rich_tracebacks=True, markup=True)
logging.basicConfig(level=LOGLEVEL, format='%(message)s',
datefmt="[%Y/%m/%d %H:%M;%S]",
handlers=[rich_handler])
return logging.getLogger('rich')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment