-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscentgather_logging.py
More file actions
30 lines (27 loc) · 1.05 KB
/
scentgather_logging.py
File metadata and controls
30 lines (27 loc) · 1.05 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
import datetime
import time
import os.path
import shutil
logfilename='logfile.log'
def log(msg,errmsg=None,dump=None,listelem=None,elemparent=None,pathname=None,depth=None):
global logfilename
ts=time.time()
logstring=[]
logstring=logstring+[datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')]
logstring=logstring+[msg,';',errmsg]
if elemparent is list and listelem in elemparent:
logstring=logstring+[elemparent.index(listelem)/len(elemparent)]
else:
logstring=logstring+[None]
logstring=logstring+[pathname,depth,dump]
print logstring
with open(logfilename,'a') as f:
f.write('\t'.join(map(str,logstring))+'\n')
def archivelog():
global logfilename
ts=time.time()
if os.path.exists(logfilename):
os.rename(logfilename,logfilename+'.'+datetime.datetime.fromtimestamp(ts).strftime('%Y%m%d%H%M%S'))
#shutil.copy(logfilename,logfilename+'.'+datetime.datetime.fromtimestamp(ts).strftime('%Y%m%d%H%M%S'))
with open(logfilename,'w') as f:
f.write('')