forked from Gnaiqing/DataSculpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogconfig.py
More file actions
21 lines (18 loc) · 952 Bytes
/
logconfig.py
File metadata and controls
21 lines (18 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import logging
import colorful
import time
# ********************************************************************
# formatter
stream_formatter = logging.Formatter('{c.white_on_black}%(levelname)s{c.reset} {c.red}%(asctime)s{c.reset} {c.blue}[%(filename)s:%(funcName)s:%(lineno)d]{c.reset} %(message)s'.format(c=colorful))
file_formatter = logging.Formatter('%(levelname)s %(asctime)s[%(filename)s:%(funcName)s:%(lineno)d]%(message)s')
# ********************************************************************
console_handler = logging.StreamHandler()
console_handler.setFormatter(stream_formatter)
timestamp = time.time()
formatted_time = time.strftime("%Y%m%d%H%M", time.localtime(timestamp))
default_file_handler=logging.FileHandler(f'logs/log_{formatted_time}.txt', 'a')
default_file_handler.setFormatter(file_formatter)
root = logging.getLogger()
root.addHandler(console_handler)
root.addHandler(default_file_handler)
root.setLevel(logging.WARNING)