Skip to main content

logging_utils

Utilities for logging and warning messages functionality.

Module

Functions

filter_stderr

def filter_stderr(to_filter: Union[str, re.Pattern])> Generator[None, None, None]:

Filter stderr messages emitted within this context manager.

Will remove any messages where the start matches the filter pattern whilst allowing any other messages to go through.

Arguments

  • to_filter: Regex pattern to match the start of messages to be filtered.

is_not_pytorch_lightning_warning

def is_not_pytorch_lightning_warning(record: logging.LogRecord)> int:

Returns 0 if is a warning generated by PyTorch Lightning, 1 otherwise.

log_pytorch_env_info_if_available

def log_pytorch_env_info_if_available()> None:

Log PyTorch environment info if PyTorch is available.

setup_loggers

def setup_loggers(    loggers: List[logging.Logger],    log_file_dir_name: Optional[str] = None,    log_level: Union[int, str] = 20,)> List[logging.Logger]:

Set up loggers with console and file handlers.

Creates a logfile in 'logs' directory with the current date and time and outputs all logs at the "DEBUG" level. Also outputs logs to stdout at the "INFO" level. A common scenario is to attach handlers only to the root logger, and to let propagation take care of the rest.

Arguments

  • loggers: The logger(s) to set up
  • log_file_dir_name: Creates a subdirectory inside BITFOUNT_LOGS_DIR if provided. Defaults to None.
  • log_level: The log level to apply to the console logs

Returns A list of updated logger(s).