-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogger.py
More file actions
102 lines (83 loc) · 2.17 KB
/
Copy pathLogger.py
File metadata and controls
102 lines (83 loc) · 2.17 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# -*- coding: utf-8 -*-
"""
Logger class that helps to print out structured logs.
Dario Niermann
2017
"""
class Logger(object):
def __init__(self,on):
self.count=1
self.count_save=[]
self.start_time=[0]
self.end_time=0
self.process_name=[""]
self.on=on #True false
def info(self,*args):
if self.on:
string="Info \t\t: "
for i in args:
string+=str(i)+" "
print( string )
def out(self,input_str,*args):
if self.on:
if self.count==1:
print( "")
for i in args:
input_str+=" "+str(i)
try:
print( str(self.count)+".","\t :",str(input_str))
self.count+=1
except:
print( "Error while logging")
def start(self,input_str,*args):
if self.on:
if self.count==1:
print( "")
for i in args:
input_str+=" "+str(i)
from time import clock
try:
print( str(self.count)+".","-"*(len(self.start_time)),"v \t:",str(input_str))
self.count_save.append(self.count)
self.count+=1
self.start_time.append(clock())
self.process_name.append(input_str)
except:
print( "Error: while begin logging")
def end(self):
if self.on:
if self.start_time[len(self.start_time)-1]!=0:
from time import clock
self.end_time=clock()
try:
print( str(self.count_save.pop())+".","-"*(len(self.start_time)-1),"^ \t:",self.process_name[len(self.process_name)-1]," (took ",str(round(self.end_time-self.start_time[len(self.start_time)-1],5))," sek)")
self.start_time.pop()
self.process_name.pop()
self.end_time=0
except:
print( "Error: while end logging")
else:
print( "Error : end log: No start time found")
def reset(self):
if self.on:
print( "------------------------------------------------")
self.count=1
if __name__=="__main__":
log=Logger(False)
log.start("Smooth")
log.start("Blur")
log.out("Decontrast")
log.end()
log.end()
a=[3,2,1]
log.info(3,a,"isadadasdasdasdasdasdasdasdasdasdasdt","a: ",a,3)
log.end()
log.reset()
log.start("test",a)
log.start("test")
log.start("test")
# log.reset()
log.end()
log.end()
log.end()
log.end()