rich#

Rich contrib functionality.

Functions#

replace_console_handlers(loggers=('luigi', 'luigi.*', 'luigi-*', 'law', 'law.*'), level=None, force_add=False, check_fn=None, **kwargs)#

Removes all tty stream handlers (i.e. those logging to stdout or stderr) from certain loggers and adds a new rich.logging.RichHandler instance with a specified level and all kwargs passed as additional options to its constructor. loggers can either be logger instances or names. In the latter case, the names are used as patterns to identify matching loggers. Unless force_add is True, no new handler is added when no tty stream handler was previously registered.

check_fn can be a function with two arguments, a logger instance and a handler instance, that should return True if that handler should be removed. When None, all handlers inheriting from the basic logging.StreamHandler are removed if their stream attibute referes to a tty stream. When level is None, it defaults to the log level of the first removed handler. In case no default level can be determined, INFO is used.

The removed handlers are returned in a list of 2-tuples (logger, removed_handlers).