-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLog.py
More file actions
50 lines (44 loc) · 1.23 KB
/
Log.py
File metadata and controls
50 lines (44 loc) · 1.23 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
import os
class Logs():
def __init__(self, filename= "logfile", printtooutput=True,curdir=os.getcwd()):
self.name = filename
self.printtooutput = printtooutput
self.curdir =curdir
def writelog(self, s):
flag = 0
f = ''
print self.curdir
try:
f = open(self.curdir + "/" + self.name + ".log", "a")
flag = 1
except:
try:
f = open(self.curdir + "/" + self.name + ".log", "w")
flag = 1
except:
flag = 0
if(flag == 1):
if self.printtooutput:
mystr = str(time.asctime(time.localtime(time.time())) + " ---- " + str(s) + '\n')
f.write(mystr)
if self.printtooutput:
print mystr
f.close()
def removelog(self):
try:
os.remove(self.curdir + "/" + self.name + ".log")
except:
a = 1
def readlog(self):
try:
f = open(self.curdir + "/" + self.name + ".log", "r")
retstr = f.read()
f.close()
except:
retstr = ""
return retstr
def exitlog(self):
return os.path.exists(self.curdir + "/" + self.name + ".log")