-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlogging_template.py
More file actions
57 lines (52 loc) · 1.26 KB
/
logging_template.py
File metadata and controls
57 lines (52 loc) · 1.26 KB
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
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2018 Jun.
@author: HuangLiPang, QuenLo
python version: 2.7
logging config doc:
https://docs.python.org/2/library/logging.config.html
"""
import logging
import logging.config
import time
from RotatingFileNameHandler import RotatingFileNameHandler
class UTCFormatter(logging.Formatter):
converter = time.gmtime
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
# local time
"standard": {
"format": "%(asctime)s - %(message)s",
"datefmt": "%Y-%m-%d %I:%M:%S %p"
},
"complete": {
"format": "%(asctime)s - PID: %(process)d"\
" - %(levelname)s - %(filename)s - %(message)s",
"datefmt": "%Y-%m-%d %I:%M:%S %p"
},
"utc": {
# "()" is a special key, which indicates a custom instantiation.
"()": UTCFormatter,
"format": "%(asctime)s %(message)s",
"datefmt": "%Y-%m-%d %I:%M:%S %p"
}
},
"handlers": {
# StreamHandler will show log in console
"default": {
"level": "INFO",
"formatter": "complete",
"class": "logging.StreamHandler"
}
},
# root logger
"root": {
"handlers": ["default"],
# default level is "WARNING"
"level": "INFO",
"propagate": True
}
}