-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.py.multipleprocesse
61 lines (53 loc) · 1.61 KB
/
logger.py.multipleprocesse
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
58
#!/usr/bin/env python
# -*- coding=utf-8 -*-
import logging.config,os,sys
base_dir = '/'.join(os.path.abspath(os.path.dirname(__file__)).split("/"))
sys.path.append(base_dir)
# http://www.cnblogs.com/restran/p/4743840.html
if os.path.exists("%s/logs"%base_dir) is not True:
os.mkdir("%s/logs"%base_dir)
logname = '%s/logs/aircraftcarrier.log'%base_dir
logging.config.dictConfig({
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'verbose': {
'format': "[%(asctime)s] [%(filename)s] [%(funcName)s] [line:%(lineno)d] [%(levelname)s] %(message)s",
'datefmt': "%Y-%m-%d %H:%M:%S"
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'handlers': {
'null': {
'level': 'DEBUG',
'class': 'logging.NullHandler',
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose'
},
'file': {
'level': 'DEBUG',
'class': 'cloghandler.ConcurrentRotatingFileHandler',
# 当达到10MB时分割日志
'maxBytes': 1024 * 1024 *10,
# 最多保留50份文件
'backupCount': 50,
# If delay is true,
# then file opening is deferred until the first call to emit().
'delay': True,
'filename': logname,
'formatter': 'verbose'
}
},
'loggers': {
'': {
'handlers': ['file'],
'level': 'INFO',
},
}
})
logger = logging.getLogger('myscript')