aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/Twisted/py2/twisted/logger/_capture.py
blob: ee9096e9db1ff642b189976db460ca052a09da66 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# -*- 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 twisted.logger import globalLogPublisher



@contextmanager
def capturedLogs():
    events = []
    observer = events.append

    globalLogPublisher.addObserver(observer)

    yield events

    globalLogPublisher.removeObserver(observer)