Linux lhjmq-records 5.15.0-118-generic #128-Ubuntu SMP Fri Jul 5 09:28:59 UTC 2024 x86_64
Your IP : 18.227.0.21
# -*- test-case-name: twisted.logger.test.test_capture -*-
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
Context manager for capturing logs.
"""
from contextlib import contextmanager
from typing import Iterator, List, Sequence, cast
from twisted.logger import globalLogPublisher
from ._interfaces import ILogObserver, LogEvent
@contextmanager
def capturedLogs() -> Iterator[Sequence[LogEvent]]:
events: List[LogEvent] = []
observer = cast(ILogObserver, events.append)
globalLogPublisher.addObserver(observer)
yield events
globalLogPublisher.removeObserver(observer)
|