diff options
author | 2021-09-07 00:15:36 +0200 | |
---|---|---|
committer | 2021-09-07 16:58:35 +0200 | |
commit | 6d7f46fabe530e4cafdffa25d7fced730965e481 (patch) | |
tree | 2576b513abe3c9c32c0910b53a56c7908869ac9d /bot/log.py | |
parent | Control logging levels through root logger instead of handlers (diff) |
Add coloredlogs
Diffstat (limited to 'bot/log.py')
-rw-r--r-- | bot/log.py | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -1,7 +1,11 @@ import logging import logging.handlers +import os +import sys from pathlib import Path +import coloredlogs + from bot.constants import Client @@ -23,6 +27,19 @@ def setup() -> None: # Console handler prints to terminal console_handler = logging.StreamHandler() + if "COLOREDLOGS_LEVEL_STYLES" not in os.environ: + coloredlogs.DEFAULT_LEVEL_STYLES = { + **coloredlogs.DEFAULT_LEVEL_STYLES, + "trace": {"color": 246}, + "critical": {"background": "red"}, + "debug": coloredlogs.DEFAULT_LEVEL_STYLES["info"], + } + + if "COLOREDLOGS_LOG_FORMAT" not in os.environ: + coloredlogs.DEFAULT_LOG_FORMAT = "%(asctime)s - %(name)s %(levelname)s: %(message)s" + + coloredlogs.install(stream=sys.stdout) + # Silence irrelevant loggers logging.getLogger("discord").setLevel(logging.ERROR) logging.getLogger("websockets").setLevel(logging.ERROR) @@ -32,7 +49,6 @@ def setup() -> None: # Setup new logging configuration logging.basicConfig( - format="%(asctime)s - %(name)s %(levelname)s: %(message)s", datefmt="%D %H:%M:%S", level=logging.TRACE if Client.debug else logging.INFO, handlers=[console_handler, file_handler], |