Skip to content

Commit 762ae05

Browse files
committed
Refactor IRISLogHandler to use logging level constants and update test logging methods to include log level in SQL query
1 parent 96bbc85 commit 762ae05

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/iop/_log_manager.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ def __init__(self, to_console: bool = False):
4141

4242
# Map Python logging levels to IRIS logging methods
4343
self.level_map = {
44-
logging.DEBUG: _iris.get_iris().cls("Ens.Util.Log").LogTrace,
45-
logging.INFO: _iris.get_iris().cls("Ens.Util.Log").LogInfo,
46-
logging.WARNING: _iris.get_iris().cls("Ens.Util.Log").LogWarning,
47-
logging.ERROR: _iris.get_iris().cls("Ens.Util.Log").LogError,
48-
logging.CRITICAL: _iris.get_iris().cls("Ens.Util.Log").LogAlert,
44+
logging.DEBUG: 5,
45+
logging.INFO: 4,
46+
logging.WARNING: 3,
47+
logging.ERROR: 2,
48+
logging.CRITICAL: 6,
4949
}
5050
# Map Python logging levels to IRIS logging Console level
5151
self.level_map_console = {
@@ -79,5 +79,5 @@ def emit(self, record: logging.LogRecord) -> None:
7979
_iris.get_iris().cls("%SYS.System").WriteToConsoleLog(self.format(record),
8080
0,self.level_map_console.get(record.levelno, 0),class_name+"."+method_name)
8181
else:
82-
log_func = self.level_map.get(record.levelno, _iris.get_iris().cls("Ens.Util.Log").LogInfo)
83-
log_func(class_name, method_name, self.format(record))
82+
log_lvl = self.level_map.get(record.levelno, 4)
83+
_iris.get_iris().cls("Ens.Util.Log").Log(log_lvl,class_name, method_name, self.format(record))

src/tests/test_commun.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,17 @@ def test_log_info_to_console_from_method(self, common, random_string):
7474
last_line = file.readlines()[-1]
7575
assert random_string in last_line
7676

77-
def _check_log_entry(self, message, method_name):
77+
def _check_log_entry(self, message, method_name, level=4):
7878
sql = """
7979
SELECT * FROM Ens_Util.Log
8080
WHERE SourceClass = '_Common'
8181
AND SourceMethod = ?
8282
AND Text = ?
83+
AND Type = ?
8384
ORDER BY id DESC
8485
"""
8586
stmt = iris.sql.prepare(sql)
86-
rs = stmt.execute(method_name, message)
87+
rs = stmt.execute(method_name, message, level)
8788
if rs is None:
8889
return []
8990
return rs
@@ -94,6 +95,12 @@ def test_log_info(self, common, random_string):
9495
for entry in rs:
9596
assert random_string in entry[9]
9697

98+
def test_log_warning(self, common, random_string):
99+
common.log_warning(random_string)
100+
rs = self._check_log_entry(random_string, 'test_log_info', 3)
101+
for entry in rs:
102+
assert random_string in entry[9]
103+
97104
def test_log_info_japanese(self, common, random_japanese):
98105
common.log_info(random_japanese)
99106
rs = self._check_log_entry(random_japanese, 'test_log_info_japanese')

0 commit comments

Comments
 (0)