# catch_logs class

(Shortest import: `from brian2.utils.logger import catch_logs)`

class brian2.utils.logger.catch_logs(log_level=30, only_from=('brian2',))

  Bases: `object`

  A context manager for catching log messages. Use this for testing the messages that are logged. Defaults to catching warning/error messages and this is probably the only real use case for testing. Note that while this context manager is active, all log messages are suppressed. Using this context manager returns a list of (log level, name, message) tuples.

  Parameters:

    log_level : int or str, optional

    > The log level above which messages are caught.

    only_from : list, optional

    > A list of module names from which messages are caught. Defaults to the `brian2` module.

    Examples :

    ——– :

    >>> logger = get_logger(‘brian2.logtest’) :

    >>> logger.warn(‘An uncaught warning’) # doctest: +SKIP :

    WARNING brian2.logtest: An uncaught warning :

    >>> with catch_logs() as l: :

    … logger.warn(‘a caught warning’) :

    … print(‘l contains: %s’ % l) :

    … :

    l contains: [(‘WARNING’, ‘brian2.logtest’, ‘a caught warning’)] :