-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
logger.py
33 lines (24 loc) · 1.33 KB
/
logger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""Custom logger."""
from sys import stdout
from loguru import logger as custom_logger
def formatter(log: dict) -> str:
"""
Format log colors based on level.
:param dict log: Logged event stored as map containing contextual metadata.
:returns: str
"""
if log["level"].name == "INFO":
return "<fg #5278a3>{time:MM-DD-YYYY HH:mm:ss}</fg #5278a3> | <fg #b3cfe7>{level}</fg #b3cfe7>: <light-white>{message}</light-white>\n"
if log["level"].name == "WARNING":
return "<fg #5278a3>{time:MM-DD-YYYY HH:mm:ss}</fg #5278a3> | <fg #b09057>{level}</fg #b09057>: <light-white>{message}</light-white>\n"
if log["level"].name == "SUCCESS":
return "<fg #5278a3>{time:MM-DD-YYYY HH:mm:ss}</fg #5278a3> | <fg #6dac77>{level}</fg #6dac77>: <light-white>{message}</light-white>\n"
if log["level"].name == "ERROR":
return "<fg #5278a3>{time:MM-DD-YYYY HH:mm:ss}</fg #5278a3> | <fg #a35252>{level}</fg #a35252>: <light-white>{message}</light-white>\n"
return "<fg #5278a3>{time:MM-DD-YYYY HH:mm:ss}</fg #5278a3> | <fg #b3cfe7>{level}</fg #b3cfe7>: <light-white>{message}</light-white>\n"
def create_logger() -> custom_logger:
"""Create custom logger."""
custom_logger.remove()
custom_logger.add(stdout, colorize=True, format=formatter)
return custom_logger
LOGGER = create_logger()