-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.py
54 lines (42 loc) · 1.41 KB
/
logger.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
import os
import queue
import threading
import time
from datetime import datetime
class logger():
def __init__(self,
logFilePath,
debug=False):
self._logFilePath = logFilePath
self._debug = debug
self._fileId = None
def logBanner(self,txt=""):
bannerStr = " **********************************************************************************************"
self.LOG(bannerStr)
self.LOG(txt)
self.LOG(bannerStr)
def initialize(self):
rtn = True
try:
self._fileId = open(self._logFilePath,"w")
self._fileId.close()
except Exception as e:
print('Error: {}'.format(e))
rtn = False
return rtn
def LOG(self, data):
rtn = True
if(self._fileId != None):
try:
now = datetime.now()
t = now.strftime("%Y:%m:%d %H:%M:%S")
temp = t + " " + data
if(self._fileId != None):
self._fileId = open(self._logFilePath,"a")
self._fileId.write(temp+"\n")
self._fileId.close()
if(self._debug):
print(temp)
except Exception as e:
print('Error: {}'.format(e))
return rtn