MCPcopy Create free account
hub / github.com/hynek/structlog / BoundLogger

Class BoundLogger

src/structlog/_generic.py:18–54  ·  view source on GitHub ↗

A generic BoundLogger that can wrap anything. Every unknown method will be passed to the wrapped *logger*. If that's too much magic for you, try `structlog.stdlib.BoundLogger` or `structlog.twisted.BoundLogger` which also take advantage of knowing the wrapped class which genera

Source from the content-addressed store, hash-verified

16
17
18class BoundLogger(BoundLoggerBase):
19 """
20 A generic BoundLogger that can wrap anything.
21
22 Every unknown method will be passed to the wrapped *logger*. If that's too
23 much magic for you, try `structlog.stdlib.BoundLogger` or
24 `structlog.twisted.BoundLogger` which also take advantage of knowing the
25 wrapped class which generally results in better performance.
26
27 Not intended to be instantiated by yourself. See
28 :func:`~structlog.wrap_logger` and :func:`~structlog.get_logger`.
29 """
30
31 def __getattr__(self, method_name: str) -> Any:
32 """
33 If not done so yet, wrap the desired logger method & cache the result.
34 """
35 if method_name == "__deepcopy__":
36 return None
37
38 wrapped = partial(self._proxy_to_logger, method_name)
39 setattr(self, method_name, wrapped)
40
41 return wrapped
42
43 def __getstate__(self) -> dict[str, Any]:
44 """
45 Our __getattr__ magic makes this necessary.
46 """
47 return self.__dict__
48
49 def __setstate__(self, state: dict[str, Any]) -> None:
50 """
51 Our __getattr__ magic makes this necessary.
52 """
53 for k, v in state.items():
54 setattr(self, k, v)

Callers 3

test_cachesMethod · 0.90
test_pickleMethod · 0.90
test_deepcopyMethod · 0.90

Calls

no outgoing calls

Tested by 3

test_cachesMethod · 0.72
test_pickleMethod · 0.72
test_deepcopyMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…