-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
log.py
42 lines (35 loc) · 1.26 KB
/
log.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
"""Custom logger configuration."""
from sys import stdout
from loguru import logger as custom_logger
def formatter(log):
"""Format log colors based on level."""
if log["level"].name == "SUCCESS":
return (
"<fg #aad1f7>{time:MM-DD-YYYY HH:mm:ss}</fg #aad1f7> | "
"<light-green>{level}</light-green>: "
"<light-white>{message}</light-white> \n"
)
if log["level"].name == "WARNING":
return (
"<fg #aad1f7>{time:MM-DD-YYYY HH:mm:ss}</fg #aad1f7> | "
"<light-yellow>{level}</light-yellow>: "
"<light-white>{message}</light-white> \n"
)
elif log["level"].name == "ERROR":
return (
"<fg #aad1f7>{time:MM-DD-YYYY HH:mm:ss}</fg #aad1f7> | "
"<light-red>{level}</light-red>: "
"<light-white>{message}</light-white> \n"
)
else:
return (
"<fg #aad1f7>{time:MM-DD-YYYY HH:mm:ss}</fg #aad1f7> | "
"<fg #67c9c4>{level}</fg #67c9c4>: "
"<light-white>{message}</light-white> \n"
)
def create_logger():
"""Create custom logger."""
custom_logger.remove()
custom_logger.add(stdout, colorize=True, format=formatter)
return custom_logger
LOGGER = create_logger()