CustomLogger#

class src.CustomLogger.CustomLogger(banner: str = '', log_file_path: str | None = None, max_old_logs: int = 25)[source]#

Bases: Formatter

Custom logger for colored terminal and file logging with sectioning and log rotation.

Parameters:
  • banner (str) – Banner to display at the top of logs.

  • log_file_path (str) – Path to the log file.

  • max_old_logs (int) – Maximum number of old log files to keep.

COLORS = {'CRITICAL': '‼', 'DEBUG': '•', 'ERROR': '✖', 'INFO': '✔', 'WARNING': '⚠'}#
append_log_to_file(line: str, filename: str | None = None) None[source]#

Append a log line to the log file.

Parameters:
  • line (str) – Log line.

  • filename (str) – Optional log file path.

close()[source]#

Close any open file handles or perform cleanup if needed.

error(msg: str) None[source]#

Log an error message.

Parameters:

msg (str) – Message to log.

format(record: LogRecord) str[source]#

Format a log record for file output.

Parameters:

record (logging.LogRecord) – Log record.

Returns:

Formatted log message.

Return type:

str

get_buffers() Tuple[List[Any], List[Any], str][source]#

Get the terminal and file log buffers and the banner.

Returns:

(terminal_buffer, file_buffer, banner)

Return type:

tuple

info(msg: str) None[source]#

Log an info message.

Parameters:

msg (str) – Message to log.

redraw_logs() None[source]#

Redraw all logs in the terminal, including the banner.

section(title: str) None[source]#

Log a section title.

Parameters:

title (str) – Section title.

strip_ansi(line: str) str[source]#

Remove ANSI color codes from a log line.

Parameters:

line (str) – Log line.

Returns:

Cleaned log line.

Return type:

str

success(msg: str) None[source]#

Log a success message.

Parameters:

msg (str) – Message to log.

warning(msg: str) None[source]#

Log a warning message.

Parameters:

msg (str) – Message to log.