Skip to content

utils.logging

Functions for convenient logging.

SeverityTracker

SeverityTracker(level=NOTSET)

Bases: Handler

Tracks the highest log-level that was sent to the logger.

If this class is added as a log handler, it can be used to check if any errors or exceptions were logged.

Attributes:

Name Type Description
highest int

The highest log-level that was sent to the logger.

get_logger

get_logger()

Returns:

Type Description
Logger

A library-specific logger instance.

setup_rich_logging

setup_rich_logging(console=None, **kwargs)

Set up a logger that uses rich markup and severity tracking.

This function is intended to be called in a script. It calls logging.basicConfig and is therefore not executed by default, as applications may wish to setup their loggers differently.

Parameters:

Name Type Description Default
console Optional[Console]

A rich.Console object to output log messages to.

None
**kwargs object

Any keyword argument will be forwarded to logging.basicConfig. If logging handlers are defined here, they will be preserved in addition to the handlers added by this function. If 'level' is not given, it will default to 'INFO'.

{}

Returns:

Type Description
SeverityTracker

The severity tracker, so that it can be used to check the highest emitted log level.