-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathLogOutput.py
More file actions
67 lines (60 loc) · 2.13 KB
/
Copy pathLogOutput.py
File metadata and controls
67 lines (60 loc) · 2.13 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
58
59
60
61
62
63
64
65
66
67
#coding:utf-8
import logging
import logging.config
import logging.handlers
import time
import idDefine as gen
import wx
class LogConsoleHandler(logging.StreamHandler):
def __init__(self, textctrl):
logging.StreamHandler.__init__(self)
self.textctrl = textctrl
def emit(self, record):
#msg = self.format(record)
#self.textctrl.AppendText(msg + "\n")
#print gen.MSG_MAX
if len(self.textctrl.GetValue()) > gen.MSG_MAX:
self.textctrl.SetValue('')
if gen.console_switch == True:
level = gen.LEVELS.get(gen.CONSOLE_LOG_LEVEL,logging.NOTSET)
if record.levelno < level:
return
tstr = time.strftime('%Y-%m-%d_%H:%M:%S.%U')
self.textctrl.AppendText("[%s]--[%s]: %s\n"%(tstr,record.levelname,record.getMessage()))
self.flush()
def LogMain():
dictLogConfig = {
"version":1,
"handlers":{
"file":{
"class":"logging.handlers.RotatingFileHandler",
"formatter":"myFormatter",
"filename": gen.LOGFILE,
"maxBytes": gen.LOG_MAX_BYTES,
"backupCount": gen.BACKUP_COUNT,
},
"consoleHandler":{
"class":"logging.StreamHandler",
"formatter":"myFormatter"
}
},
"loggers":{
"ProMonitor":{
"handlers":["file", "consoleHandler"],
"level":gen.level
}
},
"formatters":{
"myFormatter":{
"format":"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
}
}
}
logging.config.dictConfig(dictLogConfig)
#logger = logging.getLogger("wxApp")
#handler = logging.handlers.RotatingFileHandler(gen.LOGFILE,maxBytes=10000,backupCount=5,)
#logger.addHandler(handler)
LogMsg(gen.logger.debug,u"加载日志功能函数")
def LogMsg(loglevel,msg):
if gen.logswitch is True:
loglevel(msg)