fixed stacklevel correction
This commit is contained in:
+1
-1
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user