Logging#

setup_logger(log_name: AnyStr | None = 'patcher', log_filename: AnyStr | None = 'patcher.log', log_level: int | None = 20) Logger[source]#

Set up the main logger with rotating file handler.

Parameters:
  • log_name (Optional[AnyStr]) – The name of the logger, defaults to ‘patcher’.

  • log_filename (Optional[AnyStr]) – The log file name, defaults to {log_name}.log.

  • log_level (Optional[int]) – The logging level, defaults to logging.INFO.

Returns:

The configured logger.

Return type:

logging.Logger

setup_child_logger(name_of_child: AnyStr, name_of_logger: AnyStr | None = 'patcher', debug: bool | None = False) Logger[source]#

Setup a child logger for a specified context.

Parameters:
  • name_of_child (AnyStr) – The name of the child logger.

  • name_of_logger (AnyStr) – The name of the parent logger, defaults to ‘patcher’

  • debug (Optional[bool]) – Whether to set the child logger level to DEBUG, defaults to False.

Returns:

The configured child logger.

Return type:

logging.Logger

handle_traceback(exception: Exception)[source]#

Write tracebacks to logs instead of to console for readability purposes.

Parameters:

exception (Exception) – The exception instance to log.

class LogMe(class_name: AnyStr, debug: bool | None = False)[source]#

A wrapper class for logging with additional output to console using click.

Parameters:
  • class_name (AnyStr) – The name of the class for which the logger is being set up.

  • debug (Optional[bool]) – Whether to set the child logger level to DEBUG, defaults to False.

is_debug_enabled() bool[source]#

Check if debug logging is enabled.

Returns:

True if debug logging is enabled, False otherwise.

Return type:

bool

debug(msg: AnyStr)[source]#

Log a debug message and output to console if debug is enabled.

Parameters:

msg (AnyStr) – The debug message to log.

info(msg: AnyStr)[source]#

Log an info message and output to console.

Parameters:

msg (AnyStr) – The info message to log.

warning(msg: AnyStr)[source]#

Log a warning message and output to console.

Parameters:

msg (AnyStr) – The warning message to log.

error(msg: AnyStr)[source]#

Log an error message and output to console.

Parameters:

msg (AnyStr) – The error message to log.