-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.py
38 lines (32 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
34
35
36
37
import logging
import logging.handlers
import os
from colortext import ENDC
def initialize(output_dir):
"""Initialize the logging module to log messages to the right places."""
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
# console handler (INFO+)
handler = logging.StreamHandler()
handler.setLevel(logging.INFO)
formatter = logging.Formatter("%(asctime)s:%(levelname)s: %(message)s" +
ENDC)
handler.setFormatter(formatter)
logger.addHandler(handler)
# channel log (uses DEBUG)
handler = logging.FileHandler(os.path.join(output_dir, "channel.log"), "w",
encoding=None, delay="true")
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s: %(message)s" + ENDC)
handler.setFormatter(formatter)
logger.addHandler(handler)
# log everything with level name
# TODO: add color based on level
handler = logging.handlers.RotatingFileHandler(
os.path.join(output_dir, "debug.log"), "w", encoding=None, delay="true",
maxBytes=1*1024*1024, backupCount=5)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s:%(levelname)s: %(message)s" +
ENDC)
handler.setFormatter(formatter)
logger.addHandler(handler)