Skip to content

Commit b25f52f

Browse files
committed
Refactor IRISLogHandler emit method for improved readability and consistency
1 parent cb2f9f4 commit b25f52f

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

src/iop/_log_manager.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,29 @@ def emit(self, record: logging.LogRecord) -> None:
7272
Args:
7373
record: The logging record to emit
7474
"""
75-
class_name = record.class_name if hasattr(record, "class_name") else record.name # type: ignore has been added as extra attribute in LogRecord
76-
method_name = record.method_name if hasattr(record, "method_name") else record.funcName # type: ignore has been added as extra attribute in LogRecord
77-
if self.to_console or (hasattr(record, "to_console") and record.to_console): # type: ignore has been added as extra attribute in LogRecord
78-
_iris.get_iris().cls("%SYS.System").WriteToConsoleLog(self.format(record),
79-
0,self.level_map_console.get(record.levelno, 0),class_name+"."+method_name)
75+
# Extract class and method names with fallbacks
76+
class_name = getattr(record, "class_name", record.name)
77+
method_name = getattr(record, "method_name", record.funcName)
78+
79+
# Format message and get full method path
80+
message = self.format(record)
81+
method_path = f"{class_name}.{method_name}"
82+
83+
# Determine if console logging should be used
84+
use_console = self.to_console or getattr(record, "to_console", False)
85+
86+
if use_console:
87+
_iris.get_iris().cls("%SYS.System").WriteToConsoleLog(
88+
message,
89+
0,
90+
self.level_map_console.get(record.levelno, 0),
91+
method_path
92+
)
8093
else:
81-
log_lvl = self.level_map.get(record.levelno, 4)
82-
_iris.get_iris().cls("Ens.Util.Log").Log(log_lvl,class_name, method_name, self.format(record))
94+
log_level = self.level_map.get(record.levelno, 4)
95+
_iris.get_iris().cls("Ens.Util.Log").Log(
96+
log_level,
97+
class_name,
98+
method_name,
99+
message
100+
)

0 commit comments

Comments
 (0)