/
logSwitcher.py
53 lines (47 loc) · 1.74 KB
/
logSwitcher.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
49
50
51
52
53
class logSwitcher:
def __init__(self, configuration, session):
self.session = session
self.configuration = configuration
#data log for connection
import logFilenameGenerator
logFileNameFmtString = self.session['ansiLog']
logFileNameString = logFilenameGenerator.logNameGen(logFileNameFmtString, \
self.session['server'], str(session["port"]))
self.appLog = file(logFileNameString+'.app.log', 'w')
self.inputLog = file(logFileNameString+'.input.log', 'w')
#print 'logFileName'+logFileNameString
self.configuration['global']['logDetail'] = False
if self.configuration['global']['logDetail']:
self.log = self.realLog
self.debugFlag = True
self.log('debug on')
else:
self.debugFlag = False
def openLogFile(self):
import os
print self.ansiLogFilename
os.spawnv(os.P_NOWAIT, "D:/Program Files/Programmers Notepad/pn.exe", ("\"D:/Program Files/Programmers Notepad/pn.exe\"",self.ansiLogFilename))
def realLog(self, str):
self.logcnt += 1
if self.configuration['global']['logDetail']:
print '%d:%s'%(self.logcnt,str)
print >>self.appLog,str
def noLog(self, str):
pass
def switchDebug(self):
print 'calling switchDebug'
if self.debugFlag:
print 'end debug'
self.log('end debug')
self.debugFlag = False
self.log = self.noLog
#print self.log
else:
print 'start debug'
self.configuration['global']['logDetail'] = True
self.log = self.realLog
self.debugFlag = True
self.log('start debug')
#print self.log
def log(self, str):
pass