spey.system.logger.capture_logs#
- spey.system.logger.capture_logs(level: int = 10, stream=None)[source]#
Context manager that captures log records emitted while inside the context and suppresses duplicate messages. Only unique messages are printed once to the provided stream (defaults to sys.stdout).
Example:
>>> with capture_logs(logging.INFO) as _: >>> for i in range(100): >>> logging.getLogger("Spey").warning("Same warning") # printed once >>> # outputs: "Same warning" only once
- Parameters:
level (
int, defaultlogging.DEBUG) – minimum logging level to capture.stream (default
None) – file-like object to write the unique messages.