logging日志
# logging日志设置颜色
https://www.cnblogs.com/wangtaobiu/p/11987025.html
从pypi、GitHub等地方可以找到其参考文档
import logging, coloredlogs
from functools import wraps
# color logging
coloredlogs.DEFAULT_FIELD_STYLES = \
{'asctime': {'color': 'green'},
'hostname': {'color': 'magenta'},
'levelname': {'color': 'black', 'bold': True},
'module': {'color': 'blue'},
'name': {'color': 'blue'},
'programname': {'color': 'cyan'}
}
coloredlogs.DEFAULT_LEVEL_STYLES = \
{'critical': {'bold': True, 'background':'red'},
'debug': {'color': 'green'},
'error': {'color': 'red'},
'info': {},
'notice': {'color': 'magenta'},
'spam': {'color': 'green', 'faint': True},
'success': {'color': 'green', 'bold': True},
'verbose': {'color': 'blue'},
'warning': {'color': 'yellow'}
}
logger = logging.getLogger('main')
# coloredlogs.install(level='INFO', fmt='%(asctime)s,%(msecs)03d %(levelname)s %(message)s')
coloredlogs.install(level='INFO', fmt='%(asctime)s, %(levelname)s, %(module)s[%(lineno)d] %(message)s')
# Some examples.
logger.debug("this is a debugging message")
logger.info("this is an informational message")
logger.warning("this is a warning message")
logger.error("this is an error message")
logger.critical("this is a critical message")
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
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
编辑 (opens new window)
上次更新: 2021/10/11, 12:43:58