-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmrglog_demo.py
executable file
·163 lines (115 loc) · 4.9 KB
/
mrglog_demo.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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env python
import mrglog
import importlib
class A(object):
def __init__(self, level=None):
if level is None:
self.logger = mrglog.get_logger(
'A class logger', module=True)
else:
self.logger = mrglog.get_logger(
'A class logger', module=True, verbose_lvl=level)
class B(object):
def __init__(self, level=0):
self.logger = mrglog.USMLog.get_module_logger(
'B class logger', verbose_lvl=level)
def test_it(logger, a_logger, b_logger):
print('logger - verbose level {}\nA class logger - verbose level {}\n'
'B class logger - verbose level {}'.format(logger.log_lvl,
a_logger.log_lvl,
b_logger.log_lvl))
logger.error('nope error')
logger.waived('ignore it', issue='some well known issue')
logger.failed('ups fail')
logger.passed('good again')
logger.debug('some debug message')
a_logger.passed('good A1')
b_logger.failed('bad B1')
a_logger.info('some info message 1')
b_logger.fatal('some fatal message 1')
logger.testStart('test1')
logger.error('nope another error')
logger.waived('ignore it again')
logger.failed('ups fail once more')
logger.passed('and good again')
logger.warning('some warning message')
a_logger.passed('good A2')
b_logger.failed('bad B2')
b_logger.passed('good B2')
b_logger.info('some info message 2')
logger.testEnd()
a_logger.testStart('test2')
logger.waived('ignore 3')
logger.failed('fail 3')
logger.passed('good 3')
a_logger.passed('good A3')
a_logger.failed('bad A3')
b_logger.passed('good B3')
b_logger.debug('some debug message 3')
a_logger.testEnd()
b_logger.testStart('test3')
logger.waived('ignore 4')
logger.passed('good 4')
logger.rlLog('some log message', mrglog.LOG_LEVEL)
logger.log(mrglog.ERROR, 'some error message')
a_logger.passed('good A4')
b_logger.passed('good B4')
a_logger.warning('warning message 4')
b_logger.testEnd()
a_logger.close()
b_logger.close()
logger.close()
def reload_mrglog():
try:
importlib.reload(mrglog)
except AttributeError:
reload(mrglog)
print('----------------------------------------------------------------------')
print('----------------------------------------------------------------------')
print('-------------- verbose not set (prints everything) -------------------')
print('----------------------------------------------------------------------')
print('----------------------------------------------------------------------')
logger = mrglog.USMLog.get_logger('my logger 0')
a = A()
b = B()
test_it(logger, a.logger, b.logger)
print('----------------------------------------------------------------------')
print('----------------------------------------------------------------------')
print('-------- verbose set to 1 (prints only something interesting) --------')
print('----------------------------------------------------------------------')
print('----------------------------------------------------------------------')
reload_mrglog()
logger = mrglog.USMLog.get_logger('my logger 1', verbose_lvl=1)
a = A(1)
b = B(1)
test_it(logger, a.logger, b.logger)
print('----------------------------------------------------------------------')
print('----------------------------------------------------------------------')
print('------------- verbose set to 2 (prints only log messages) ------------')
print('----------------------------------------------------------------------')
print('----------------------------------------------------------------------')
reload_mrglog()
logger = mrglog.USMLog.get_logger('my logger 2', verbose_lvl=2)
a = A(2)
b = B(2)
test_it(logger, a.logger, b.logger)
print('----------------------------------------------------------------------')
print('----------------------------------------------------------------------')
print('--------------------- verbose levels combination ---------------------')
print('----------------------------------------------------------------------')
print('----------------------------------------------------------------------')
reload_mrglog()
logger = mrglog.USMLog.get_logger('my logger 3', verbose_lvl=2)
a = A()
b = B(1)
test_it(logger, a.logger, b.logger)
print('----------------------------------------------------------------------')
print('----------------------------------------------------------------------')
print('--------- xml and txt output test (look for logs directory) ----------')
print('----------------------------------------------------------------------')
print('----------------------------------------------------------------------')
reload_mrglog()
logger = mrglog.USMLog.get_logger('my logger 3', output=['std', 'xml', 'txt'])
a = A()
b = B()
test_it(logger, a.logger, b.logger)