Log capturing#

logot makes it easy to capture logs from the stdlib logging module:

with Logot().capturing() as logot:
   do_something()
   logot.assert_logged(logged.info("App started"))

See also

See Logging frameworks for other supported logging frameworks (e.g. loguru).

Test framework integrations#

Use a supported test framework integration for automatic log capturing in tests:

Configuring#

The Logot.capturing() method defaults to capturing all records from the root logger. Customize this with the level and logger arguments to Logot.capturing():

with Logot().capturing(level=logging.WARNING, logger="app") as logot:
   do_something()
   logot.assert_logged(logged.info("App started"))

For advanced use-cases, multiple Logot.capturing() calls on the same Logot instance are supported. Be careful to avoid capturing duplicate logs with overlapping calls to Logot.capturing()!

See also

See Logot and Logot.capturing() API reference.