-
Notifications
You must be signed in to change notification settings - Fork 13
/
log.py
60 lines (40 loc) · 1.1 KB
/
log.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
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
# This files handles log messages with support for different log-modes.
# Author: Stefan Kahl, 2018, Chemnitz University of Technology
import sys
sys.path.append("..")
import config as cfg
log = ''
def show(s, new_line=False):
global log
if isinstance(s, (list, tuple)):
for i in range(len(s)):
print s[i],
log += str(s[i])
if i < len(s) - 1:
log += ' '
else:
print s,
log += str(s)
if new_line:
print ''
log += '\n'
else:
log += ' '
def i(s, new_line=True):
if cfg.LOG_MODE in ['all', 'info']:
show(s, new_line)
def p(s, new_line=True):
if cfg.LOG_MODE in ['all', 'progress']:
show(s, new_line)
def e(s, new_line=True):
if cfg.LOG_MODE in ['all', 'error']:
show(s, new_line)
def r(s, new_line=True):
if cfg.LOG_MODE in ['all', 'result']:
show(s, new_line)
def clear():
global log
log = ''
def export():
with open(cfg.LOG_FILE, 'w') as lfile:
lfile.write(log)