Created
July 22, 2021 13:27
-
-
Save bryaneaton/ff4e285e6e9d5014e5086daa719451ec to your computer and use it in GitHub Desktop.
Useful logging class for python!
This file contains hidden or 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
#!/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