๐Ÿ“ฆ ftnext / python-logging-practice

๐Ÿ“„ richhandler_example.py ยท 25 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25import logging
import sys

# from pythonjsonlogger.json import JsonFormatter
from rich.logging import RichHandler

from awesomelib import awesome

if len(sys.argv) > 1 and sys.argv[1] == "-v":
    log_level = logging.DEBUG
else:
    log_level = logging.WARNING

rich_handler = RichHandler()
# rich_handler.setFormatter(
#     JsonFormatter("%(name)s:%(funcName)s - %(message)s", json_ensure_ascii=False)
# )
logging.basicConfig(
    level=log_level,
    format="%(name)s:%(funcName)s - %(message)s",
    handlers=[rich_handler],
)

awesome()