Skip to content

Commit f506c74

Browse files
authored
Merge pull request #29 from alaaalii/master
Add exception log function and tests
2 parents 43e706f + 5fd8d51 commit f506c74

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

qpylib/log_qpylib.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def _choose_log_fn(level):
5353
'DEBUG': QLOGGER.debug,
5454
'WARNING': QLOGGER.warning,
5555
'ERROR': QLOGGER.error,
56+
'EXCEPTION': QLOGGER.exception,
5657
'CRITICAL': QLOGGER.critical
5758
}.get(level.upper(), QLOGGER.info)
5859

@@ -62,6 +63,7 @@ def _map_notification_code(level):
6263
'DEBUG': "0000006000",
6364
'WARNING': "0000004000",
6465
'ERROR': "0000003000",
66+
'EXCEPTION': "0000003000",
6567
'CRITICAL': "0000003000"
6668
}.get(level.upper(), "0000006000")
6769

test/test_logging.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,14 @@ def test_all_log_levels_with_manifest_info_threshold(set_console_ip, info_thresh
9090
qpylib.log('hello warning', 'WARNING')
9191
qpylib.log('hello error', 'ERROR')
9292
qpylib.log('hello critical', 'CRITICAL')
93+
qpylib.log('hello exception', 'EXCEPTION')
9394
verify_log_file_content(log_path, [
9495
{'level': 'INFO', 'text': 'hello default info'},
9596
{'level': 'INFO', 'text': 'hello info'},
9697
{'level': 'WARNING', 'text': 'hello warning'},
9798
{'level': 'ERROR', 'text': 'hello error'},
98-
{'level': 'CRITICAL', 'text': 'hello critical'}],
99+
{'level': 'CRITICAL', 'text': 'hello critical'},
100+
{'level': 'ERROR', 'text': 'hello exception'}],
99101
not_expected_lines=[{'level': 'DEBUG', 'text': 'hello debug'}])
100102

101103
def test_all_log_levels_with_manifest_debug_threshold(set_console_ip, debug_threshold, tmpdir):
@@ -109,13 +111,15 @@ def test_all_log_levels_with_manifest_debug_threshold(set_console_ip, debug_thre
109111
qpylib.log('hello warning', 'WARNING')
110112
qpylib.log('hello error', 'ERROR')
111113
qpylib.log('hello critical', 'CRITICAL')
114+
qpylib.log('hello exception', 'EXCEPTION')
112115
verify_log_file_content(log_path, [
113116
{'level': 'DEBUG', 'text': 'hello debug'},
114117
{'level': 'INFO', 'text': 'hello default info'},
115118
{'level': 'INFO', 'text': 'hello info'},
116119
{'level': 'WARNING', 'text': 'hello warning'},
117120
{'level': 'ERROR', 'text': 'hello error'},
118-
{'level': 'CRITICAL', 'text': 'hello critical'}])
121+
{'level': 'CRITICAL', 'text': 'hello critical'},
122+
{'level': 'ERROR', 'text': 'hello exception'}])
119123

120124
def test_all_log_levels_with_set_debug_threshold(set_console_ip, info_threshold, tmpdir):
121125
log_path = os.path.join(tmpdir.strpath, 'app.log')
@@ -129,13 +133,15 @@ def test_all_log_levels_with_set_debug_threshold(set_console_ip, info_threshold,
129133
qpylib.log('hello warning', 'WARNING')
130134
qpylib.log('hello error', 'ERROR')
131135
qpylib.log('hello critical', 'CRITICAL')
136+
qpylib.log('hello exception', 'EXCEPTION')
132137
verify_log_file_content(log_path, [
133138
{'level': 'DEBUG', 'text': 'hello debug'},
134139
{'level': 'INFO', 'text': 'hello default info'},
135140
{'level': 'INFO', 'text': 'hello info'},
136141
{'level': 'WARNING', 'text': 'hello warning'},
137142
{'level': 'ERROR', 'text': 'hello error'},
138-
{'level': 'CRITICAL', 'text': 'hello critical'}])
143+
{'level': 'CRITICAL', 'text': 'hello critical'},
144+
{'level': 'ERROR', 'text': 'hello exception'}])
139145

140146
def test_all_log_levels_with_set_warning_threshold(set_console_ip, info_threshold, tmpdir):
141147
log_path = os.path.join(tmpdir.strpath, 'app.log')
@@ -149,10 +155,12 @@ def test_all_log_levels_with_set_warning_threshold(set_console_ip, info_threshol
149155
qpylib.log('hello warning', 'WARNING')
150156
qpylib.log('hello error', 'ERROR')
151157
qpylib.log('hello critical', 'CRITICAL')
158+
qpylib.log('hello exception', 'EXCEPTION')
152159
verify_log_file_content(log_path, [
153160
{'level': 'WARNING', 'text': 'hello warning'},
154161
{'level': 'ERROR', 'text': 'hello error'},
155-
{'level': 'CRITICAL', 'text': 'hello critical'}],
162+
{'level': 'CRITICAL', 'text': 'hello critical'},
163+
{'level': 'ERROR', 'text': 'hello exception'}],
156164
not_expected_lines=[
157165
{'level': 'DEBUG', 'text': 'hello debug'},
158166
{'level': 'INFO', 'text': 'hello default info'},
@@ -178,10 +186,12 @@ def test_set_log_level_with_bad_level_uses_info(set_console_ip, debug_threshold,
178186
qpylib.log('hello warning', 'WARNING')
179187
qpylib.log('hello error', 'ERROR')
180188
qpylib.log('hello critical', 'CRITICAL')
189+
qpylib.log('hello exception', 'EXCEPTION')
181190
verify_log_file_content(log_path, [
182191
{'level': 'INFO', 'text': 'hello default info'},
183192
{'level': 'INFO', 'text': 'hello info'},
184193
{'level': 'WARNING', 'text': 'hello warning'},
185194
{'level': 'ERROR', 'text': 'hello error'},
186-
{'level': 'CRITICAL', 'text': 'hello critical'}],
195+
{'level': 'CRITICAL', 'text': 'hello critical'},
196+
{'level': 'ERROR', 'text': 'hello exception'}],
187197
not_expected_lines=[{'level': 'DEBUG', 'text': 'hello debug'}])

0 commit comments

Comments
 (0)