fixed stacklevel correction

This commit is contained in:
2023-12-12 17:03:58 +01:00
parent 4b92006d9d
commit 2bbf6df7bd
2 changed files with 2 additions and 3 deletions
+1 -1
View File
@@ -16,7 +16,7 @@ class Traceable:
combined = ", ".join(combined)
line = f"{cls_name}({combined})"
log.trace(f"creating: {line}")
log.trace(f"creating: {line}", stacklevel=2) # increase stacklevel by 1 to skip Registry
return super().__new__(cls)
+1 -2
View File
@@ -27,8 +27,7 @@ def add_log_Level(logger, level_name, level_value, func_name=None, color=None):
def log_func_for_class(self, *args, **kwargs):
if sys.version_info >= (3,8): #TODO: how to do this for <=3.7
stacklevel = kwargs.get("stacklevel", 1)
# stacklevel += 3 # Traceable with stacklevel=1: 0 logcfg => 1 debug => 2 registry => 3 actual location
stacklevel += 2 # import logging: 0 logcfg (log_func_for_class) => 1 logcfg (import_with_log) => 2 actual location
stacklevel += 2 # 0 here => 1 call to log.trace() => 2 actual location
kwargs["stacklevel"] = stacklevel
self.log(level_value, *args, **kwargs)