-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLog.py
More file actions
70 lines (56 loc) · 1.27 KB
/
Copy pathLog.py
File metadata and controls
70 lines (56 loc) · 1.27 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
68
69
70
#!/usr/bin/python
from zigutils import *
from datetime import datetime
class Log :
log_file = None
elog_file = None
dlog_file = None
log_stdout = True
@classmethod
def init(cls,filename=None) :
if filename :
cls.log_file = open(filename,'a')
cls.elog_file = cls.log_file
cls.dlog_file = cls.log_file
cls.log_stdout = False
else :
cls.log_file = open("log.txt",'a')
cls.elog_file = open("error.txt",'a')
cls.dlog_file = open("debug.txt",'a')
cls.log_stdout = True
@classmethod
def log(cls,*args) :
s = cls.buildString(*args)
cls.log_file.write(s + "\n")
if cls.log_stdout :
print s
else :
cls.log_file.flush()
@classmethod
def elog(cls,*args) :
s = cls.buildString(*args)
cls.elog_file.write(s + "\n")
if cls.log_stdout :
print s
else :
cls.elog_file.flush()
@classmethod
def dlog(cls,*args) :
s = cls.buildString(*args)
cls.dlog_file.write(s + "\n")
if cls.log_stdout :
print s
else :
cls.dlog_file.flush()
@classmethod
def buildString(cls,*args) :
date_str = datetime.now().strftime("%b %e %Y %H:%M:%S")
func_str = Func(3)
s = date_str + ' ' + func_str + ' ' + ' '.join(map(str,args))
return s
def elog(*args) :
Log.elog(*args)
def dlog(*args) :
Log.dlog(*args)
def log(*args) :
Log.log(*args)