-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.py
48 lines (39 loc) · 1.87 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
import logging.handlers
import setting
LOG_FORMAT = "[%(levelname)s %(asctime)s %(process)d %(filename)s:%(funcName)s:%(lineno)s] %(message)s"
#LOG_FORMAT = "%(asctime)s %(pathname)s %(filename)s %(funcName)s %(lineno)s %(levelname)s - %(message)s", "%Y-%m-%d %H:%M:%S"
# logging.basicConfig(filename=setting.FlaskSettings.LOG_PATH, format=LOG_FORMAT, level=logging.INFO)
# filehandler = logging.handlers.TimedRotatingFileHandler(
# setting.LOG_PATH, 'M', 1, 0)
# update by day at midnight
# filehandler = logging.handlers.TimedRotatingFileHandler(
# setting.FlaskSettings.LOG_PATH, 'midnight', 1, 0)
info_logger=logging.getLogger("__info__")
we_logger=logging.getLogger("__we__")
index_logger=logging.getLogger("__index__")
info_filehandler = logging.handlers.TimedRotatingFileHandler(
setting.FlaskSettings.INFO_LOG_PATH, 'midnight', 1, 0)
we_filehandler = logging.handlers.TimedRotatingFileHandler(
setting.FlaskSettings.WE_LOG_PATH, 'midnight', 1, 0)
index_filehandler = logging.handlers.TimedRotatingFileHandler(
setting.FlaskSettings.INDEX_LOG_PATH, 'midnight', 1, 0)
info_filehandler.suffix = "%Y-%m-%d_%H-%M-%S.log"
we_filehandler.suffix = "%Y-%m-%d_%H-%M-%S.log"
index_filehandler.suffix = "%Y-%m-%d_%H-%M-%S.log"
# 打印到屏幕设置
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)
# 打印到文件设置
# pic_diff_logger = logging.getLogger()
info_logger.setLevel(logging.INFO)
we_logger.setLevel(logging.WARNING)
index_logger.setLevel(logging.INFO)
we_filehandler.setFormatter(logging.Formatter(LOG_FORMAT))
info_filehandler.setFormatter(logging.Formatter(LOG_FORMAT))
index_filehandler.setFormatter(logging.Formatter(LOG_FORMAT))
# pic_diff_logger.addHandler(filehandler)
# app.logger.addHandler(filehandler)
info_logger.addHandler(ch)
info_logger.addHandler(info_filehandler)
we_logger.addHandler(we_filehandler)
index_logger.addHandler(index_filehandler)