added Traceable mix-in

This commit is contained in:
2023-12-08 12:47:18 +01:00
parent 6139ed9f0a
commit a7dcb869dd
+29
View File
@@ -0,0 +1,29 @@
from logzero import logger as log
class Traceable:
def __new__(cls, *args, **kwargs):
cls_name = cls.__name__
printable_args = [short_repr(i) for i in args]
printable_kwargs = [f"{k}={short_repr(v)}" for k, v in kwargs.items()]
combined = printable_args + printable_kwargs
combined = ", ".join(combined)
line = f"{cls_name}({combined})"
log.trace(f"creating: {line}")
return super().__new__(cls)
def short_repr(string, cutoff=20):
res = repr(string)
if len(res) > cutoff:
res = res[:cutoff] + "..."
return res