Last active
September 7, 2022 14:24
-
-
Save sempervent/9c68aafc8df6b3f4b99ce9e1e1c24d2e to your computer and use it in GitHub Desktop.
Easy creation of beautiful Rich logging in 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
Usage: