-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathlogger.py
44 lines (30 loc) · 914 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
39
40
41
42
43
44
import sys, time
logfile = None
def log(category, message, console = True):
global logfile
categories = ['INFO','WARNING','ERROR','SUCCESS']
cat_len = max(map(len,categories))
logtext = '%*s %s\n' % (-(cat_len + 1),category+':',message)
if console:
sys.stderr.write(logtext)
if logfile:
logfile.write(logtext)
def init_logfile(filename):
global logfile
logfile = open(filename,'a')
logfile.write("""\
*******************************************************
Initializing Log File: %s
*******************************************************
""" % time.ctime())
def check_logfile():
global logfile
if logfile:
return logfile.name
else:
return None
def close_logfile():
global logfile
if logfile:
logfile.close()
logfile = None