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

Class CapturingLogger

src/structlog/testing.py:170–198  ·  view source on GitHub ↗

Store the method calls that it's been called with. This is nicer than `ReturnLogger` for unit tests because the bound logger doesn't have to cooperate. **Any** method name is supported. .. versionadded:: 20.2.0

Source from the content-addressed store, hash-verified

168
169
170class CapturingLogger:
171 """
172 Store the method calls that it's been called with.
173
174 This is nicer than `ReturnLogger` for unit tests because the bound logger
175 doesn't have to cooperate.
176
177 **Any** method name is supported.
178
179 .. versionadded:: 20.2.0
180 """
181
182 calls: list[CapturedCall]
183
184 def __init__(self) -> None:
185 self.calls = []
186
187 def __repr__(self) -> str:
188 return f"<CapturingLogger with {len(self.calls)} call(s)>"
189
190 def __getattr__(self, name: str) -> Any:
191 """
192 Capture call to `calls`
193 """
194
195 def log(*args: Any, **kw: Any) -> None:
196 self.calls.append(CapturedCall(name, args, kw))
197
198 return log
199
200
201class CapturingLoggerFactory:

Callers 4

test_reprMethod · 0.90
test_capturesMethod · 0.90
_clFunction · 0.90
__init__Method · 0.85

Calls

no outgoing calls

Tested by 4

test_reprMethod · 0.72
test_capturesMethod · 0.72
_clFunction · 0.72
__init__Method · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…