supercontest.util.logging

Utilities to assist with logging for the entire application.

Functions

create_handler

Creates the standard streamhandler, with supercontest-specific format.

print_data

Takes a list of data and prints the desired keys in columns as defined by the input widths.

show_loggers

Helpful printer to show the tree of loggers in the current app.

supercontest.util.logging.create_handler() Handler

Creates the standard streamhandler, with supercontest-specific format. Then attach it to any logger. Example: logging.getLogger("mylogger").addHandler(create_handler())

Returns:

A formatted stream handler.

supercontest.util.logging.print_data(data: list[dict[str, Any]], keys: list[str], widths: list[int])

Takes a list of data and prints the desired keys in columns as defined by the input widths. Separates each column by a space, and surrounds each column with brackets. This intentionally prints to stdout, rather than a custom logger.

Parameters:
  • data – The data to print, each item a row, in order.

  • keys – The keys to print as cols, in order.

  • widths – The width of the cols to print, in order.

supercontest.util.logging.show_loggers(attrs: list[str] | None = None)

Helpful printer to show the tree of loggers in the current app. Will pretty-print them to stdout alphabetically, with the desired attributes. Some rules:

  • If the attr doesn’t exist for a logger, it will print None.

  • If the attr is a list, it will print a joined string of the items.

  • If the attr is “level”, it will cast to the logger’s name (not number, the default).

  • If the attr is anything else, it will just str() the attr value.

Parameters:

attrs – The columns to print for each logger. Defaults to name, level, parent, handlers, propagate.