f_lib.logging.utils module

Logging utilities.

f_lib.logging.utils.is_stream_handler(handler: logging.Handler, streams: Iterable[TextIO] | None = None) bool[source]

Whether a stream handlers writing to the given streams(s).

Parameters:
  • handler – The logging.Handler to check.

  • streams – An array of streams to match against.

f_lib.logging.utils.find_handler(logger: LoggerTypeVar, match_handler: Callable[[logging.Handler], bool] = is_stream_handler) tuple[logging.Handler, LoggerTypeVar] | tuple[None, None][source]

Find logging.Handler`(s) in the propagation tree of a :class:`~logging.Logger.

This function finds a logging.Handler attached to a logger or one of it’s parents (see walk_propagation_tree()).

Parameters:
  • logger – The Logger to check.

  • match_handler – A callable that receives a Handler object and returns True to match a handler or False to skip that handler and continue searching for a match.

Returns:

  1. The matched Handler object or None

    if no handler was matched.

  2. The Logger object to which the handler is

    attached or None if no handler was matched.

Return type:

A tuple of two values

f_lib.logging.utils.optionally_replace_handler(logger: LoggerTypeVar, *, match_handler: Callable[[logging.Handler], bool] = is_stream_handler, reconfigure: bool = False) tuple[logging.Handler | None, LoggerTypeVar][source]

Prepare to replace a handler if needed and configured to do so.

Parameters:
  • logger – The Logger to optionally replace the handler for.

  • match_handler – A callable that receives a Handler object and returns True to match a handler or False to skip that handler and continue searching for a match.

  • reconfigure – Whether to replace an existing Handler.

Returns:

  1. The matched Handler object or None

    if no handler was matched.

  2. The Logger to which the matched handler was

    attached or the logger given to replace_handler().

Return type:

A tuple of two values

f_lib.logging.utils.walk_propagation_tree(logger: LoggerTypeVar | None) Iterator[LoggerTypeVar][source]

Walk through the propagation hierarchy of the given logger.

Parameters:

logger – The logger whose hierarchy to walk (a Logger object).

Yields:

Logger objects.