-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup_logging.py
41 lines (33 loc) · 1.37 KB
/
setup_logging.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
import logging
import os
import sys
from src.utils.formatter import LoggingFormatter
def setup(name='debug') -> logging.Logger:
logger = logging.getLogger(name)
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(LoggingFormatter(
'{color}[{module}][{asctime}] [Thread: {thread}] [{levelname}]:{colorend} {message}',
datefmt='%Y-%m-%d %H:%M:%S', style='{'))
logger.addHandler(handler)
db_logger = logging.getLogger('database')
if level := os.environ.get('LEVEL'):
db_logger.setLevel(level)
else:
db_logger.setLevel(logging.WARNING)
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(LoggingFormatter(
'{color}[{module}][{asctime}] [Thread: {thread}] [{levelname}]:{colorend} {message}',
datefmt='%Y-%m-%d %H:%M:%S', style='{'))
db_logger.addHandler(handler)
discord_webhook_logging = logging.getLogger('webhook')
if level:
discord_webhook_logging.setLevel(level)
else:
discord_webhook_logging.setLevel(logging.WARNING)
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(LoggingFormatter(
'{color}[{module}][{asctime}] [Thread: {thread}] [{levelname}]:{colorend} {message}',
datefmt='%Y-%m-%d %H:%M:%S', style='{'))
discord_webhook_logging.addHandler(handler)
return logger