CodeEntropy.core.logging module

Logging configuration utilities for CodeEntropy.

This module configures consistent logging across the project with:

  • Rich console output (with tracebacks) for human-readable terminal logs

  • File handlers for main logs, error-only logs, command logs, and MDAnalysis logs

  • A singleton Rich Console instance with recording enabled, so terminal output can be exported to disk at the end of a run

The design keeps responsibilities separated: - ErrorFilter: filter logic only - LoggingConfig: handler creation, logger wiring, and exporting recorded output

class CodeEntropy.core.logging.ErrorFilter(name='')[source]

Bases: Filter

Allow only ERROR and CRITICAL log records.

This filter is intended for the error file handler so that the file contains only high-severity records and does not include DEBUG/INFO/WARNING output.

filter(record: LogRecord) bool[source]

Return True if the record should be logged.

Parameters:

record – The log record being evaluated.

Returns:

True if record.levelno >= logging.ERROR, otherwise False.

class CodeEntropy.core.logging.LoggingConfig(folder: str, level: int = 20)[source]

Bases: object

Configure project logging with Rich console output and file handlers.

This class wires a set of handlers onto the root logger and a few named loggers. It also provides a singleton Rich Console instance with recording enabled so that all console output can be exported to a text file later.

Variables:
  • log_dir – Directory where log files are written.

  • level – Base logging level for the root logger and file handlers.

  • console – Shared Rich Console instance used by RichHandler.

  • handlers – Mapping of handler name to handler instance.

configure() Logger[source]

Attach configured handlers to the appropriate loggers.

This method: - Attaches rich/main/error handlers to the root logger - Attaches command handler to the ‘commands’ logger (non-propagating) - Attaches MDAnalysis handler to the ‘MDAnalysis’ logger (non-propagating)

Returns:

A logger for the current module.

export_console(filename: str = 'program_output.txt') None[source]

Save recorded console output to a file.

Parameters:

filename – Output filename inside the log directory.

classmethod get_console() Console[source]

Get or create the singleton Rich Console with recording enabled.

Returns:

A Rich Console instance that prints to terminal and records output.

set_level(log_level: int) None[source]

Update logging levels for root and named loggers.

Notes

  • FileHandlers are set to the new log_level.

  • RichHandler is kept at INFO (or higher) for cleaner console output.

Parameters:

log_level – New logging level (e.g., logging.DEBUG).