forked from egcodes/aristotle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LogHandler.py
33 lines (28 loc) · 1.02 KB
/
LogHandler.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
import sys
import traceback
from datetime import datetime
class LogHandler:
def __init__(self, className):
self.className = className
def printMsg(self, message, tabStop=0):
if not tabStop:
print "\t" * tabStop + "* %s"%message
elif tabStop == 1:
print "\t" * tabStop + "# %s"%message
elif tabStop == 2:
print "\t" * tabStop + "- %s"%message
elif tabStop == 3:
print "\t" * tabStop + ". %s"%message
sys.stdout.flush()
# Hata ve uyarilarin loglanmasi
def logger(self, function, message=""):
#Dosyaya
with open("error.log", "a") as f:
f.writelines("[%s]\n%s.%s %s\n"%(str(datetime.now())[:19], self.className, function, message))
traceback.print_exc(file=f)
f.writelines("\n")
#Ekrana
print "[%s]\n%s.%s %s\n"%(str(datetime.now())[:19], self.className, function, message),
print traceback.format_exc()
print "\n"
sys.stdout.flush()