-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwritelog.py
More file actions
22 lines (21 loc) · 876 Bytes
/
writelog.py
File metadata and controls
22 lines (21 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from datetime import datetime
import os
class writeLog:
def __init__(self,option=None):
if option:
if os.path.isdir("./logs-%s" % option) == False:
os.mkdir("./logs-%s" % option)
self.filename = 'logs-%s/' % option + datetime.now().strftime("%Y-%m-%d-%H-%M") + '.text'
else:
if os.path.isdir("./logs") == False:
os.mkdir("./logs")
self.filename = 'logs/' + datetime.now().strftime("%Y-%m-%d-%H-%M") + '.text'
print('logfile : ' + self.filename)
def writeLog(self,mode,text):
text = text + "\n"
with open(self.filename,'a') as f:
time = datetime.now().strftime("%H:%M:%S")
if mode == 'system':
f.write(time + ' : system --> ' + text)
else:
f.write(time + ' : user --> ' + text)