-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
logger.py
58 lines (48 loc) · 1.59 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""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: Dictionary containing log level, details, etc.
:returns: str
"""
if log["level"].name == "INFO":
return (
"<fg #aad1f7>{time:HH:mm:ss A}</fg #aad1f7> | "
"<fg #cfe2f3>{level}</fg #cfe2f3>: "
"<light-white>{message}</light-white> \n"
)
if log["level"].name == "SUCCESS":
return (
"<fg #aad1f7>{time:HH:mm:ss A}</fg #aad1f7> | "
"<fg #85de83>{level}</fg #85de83>: "
"<light-white>{message}</light-white> \n"
)
if log["level"].name == "WARNING":
return (
"<fg #aad1f7>{time:HH:mm:ss A}</fg #aad1f7> | "
"<light-yellow>{level}</light-yellow>: "
"<light-white>{message}</light-white> \n"
)
elif log["level"].name == "ERROR":
return (
"<fg #aad1f7>{time:HH:mm:ss A}</fg #aad1f7> | "
"<light-red>{level}</light-red>: "
"<light-white>{message}</light-white> \n"
)
else:
return (
"<fg #aad1f7>{time:HH:mm:ss A}</fg #aad1f7> | "
"<fg #67c9c4>{level}</fg #67c9c4>: "
"<light-white>{message}</light-white> \n"
)
def create_logger() -> custom_logger:
"""
Create custom logger.
:returns: custom_logger
"""
custom_logger.remove()
custom_logger.add(stdout, colorize=True, format=formatter)
return custom_logger
LOGGER = create_logger()