_capture.py 459 B

123456789101112131415161718192021222324
  1. # -*- test-case-name: twisted.logger.test.test_capture -*-
  2. # Copyright (c) Twisted Matrix Laboratories.
  3. # See LICENSE for details.
  4. """
  5. Context manager for capturing logs.
  6. """
  7. from contextlib import contextmanager
  8. from twisted.logger import globalLogPublisher
  9. @contextmanager
  10. def capturedLogs():
  11. events = []
  12. observer = events.append
  13. globalLogPublisher.addObserver(observer)
  14. yield events
  15. globalLogPublisher.removeObserver(observer)