potpyri.utils.logger

Logging utilities for the POTPyRI pipeline.

Provides a colored console and file logger with UTC timestamps for pipeline steps. Authors: Kerry Paterson, Charlie Kilpatrick.

Functions

formatter_message(message[, use_color])

Replace $RESET and $BOLD placeholders with ANSI codes or empty strings.

get_log(log_dir)

Create and return a ColoredLogger writing to the given directory.

Classes

ColoredFormatter(msg[, use_color])

Formatter that optionally colors the levelname in log records.

ColoredLogger(filename)

Logger that writes to both console (colored) and a file (UTC, no color).

class potpyri.utils.logger.ColoredFormatter(msg, use_color=True)[source]

Bases: Formatter

Formatter that optionally colors the levelname in log records.

format(record)[source]

Format the log record; optionally colorize levelname.

class potpyri.utils.logger.ColoredLogger(filename)[source]

Bases: Logger

Logger that writes to both console (colored) and a file (UTC, no color).

FILE_FORMAT = '[%(asctime)s::%(filename)s::%(lineno)d] [%(levelname)s] %(message)s'
F_FMT = '[$BOLD%(asctime)s::%(filename)s::%(lineno)d$RESET] [%(levelname)s] %(message)s'
STREAM_FORMAT = '[\x1b[1m%(filename)s::%(lineno)d\x1b[0m] [%(levelname)s]  %(message)s'
ST_FMT = '[$BOLD%(filename)s::%(lineno)d$RESET] [%(levelname)s]  %(message)s'
close()[source]

Close and remove all handlers.

Call when the logger is no longer needed (e.g., end of test or script) to avoid ResourceWarnings from unclosed file handles.

shutdown()[source]

Shut down the logging system and flush all handlers.

potpyri.utils.logger.formatter_message(message, use_color=True)[source]

Replace $RESET and $BOLD placeholders with ANSI codes or empty strings.

Parameters:
  • message (str) – Format string possibly containing $RESET and $BOLD.

  • use_color (bool, optional) – If True, insert color sequences; otherwise strip them. Default is True.

Returns:

Message with placeholders substituted.

Return type:

str

potpyri.utils.logger.get_log(log_dir)[source]

Create and return a ColoredLogger writing to the given directory.

Log filename is generated as log_YYYYMMDD_HHMMSS.log (UTC).

Parameters:

log_dir (str) – Directory path for the log file.

Returns:

Logger instance with stream and file handlers.

Return type:

ColoredLogger