-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogger.py
40 lines (30 loc) · 873 Bytes
/
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
#!/usr/bin/python3
import datetime
import time
DEBUG=1
INFO=2
WARNING=4
ERROR=8
class Logger:
def __init__(self, lvl = INFO):
self.DEBUGLEVEL = lvl
def shouldLog(self, lvl = INFO):
return (lvl >= self.DEBUGLEVEL)
@staticmethod
def errorcodeToString(code):
if code == DEBUG:
return 'DEBUG'
if code == INFO:
return 'INFO'
if code == WARNING:
return 'WARNING'
if code == ERROR:
return 'ERROR'
def __call__(self,LEVEL, txt):
if LEVEL >= self.DEBUGLEVEL:
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
print ('%s %-7s: %s' % (st, self.errorcodeToString(LEVEL), str(txt)))
if __name__ == '__main__':
log=Logger(DEBUG)
log(DEBUG, 'hei')