-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmylog.py
More file actions
56 lines (44 loc) · 1.31 KB
/
mylog.py
File metadata and controls
56 lines (44 loc) · 1.31 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
#########################
#
# Python module to print messages to a log file
#
# this should probably be replaced with python module: logger
#
# The intent is for this to be imported into another script
#
#########################
#########################
import time
import datetime
global LogObject
def setLogObject(o):
global LogObject
LogObject = o
def getLogObject():
return LogObject
#########################
class mylog:
def __init__(self, path, logfile):
self.Path = path
self.LogFile = self.Path + "/" + logfile
# changing to append so it can be added to action scripts
self.LogFileObject = open(self.LogFile, 'a+')
self.Debug = False
def closeLogFile(self):
self.LogFileObject.close()
def setDebug(self, debug):
self.Debug = debug
# Log messages should be time stamped
def timeStamp(self):
t = time.time()
s = datetime.datetime.fromtimestamp(t).strftime('%Y/%m/%d %H:%M:%S - ')
return s
# Write messages in a standard format
def printMsg(self, s):
if s == '':
self.LogFileObject.write("\n")
else:
self.LogFileObject.write(self.timeStamp() + s + "\n")
if self.Debug:
print(self.timeStamp() + s)
self.LogFileObject.flush()