photon_mosaic_pipeline.logging_config#

Logging configuration for photon-mosaic-pipeline with formatting and colors.

Functions

ensure_dir(path[, mode, parents, exist_ok])

Create a directory (Path or str) with optional permission setting.

log_list_summary(logger, items, item_type[, ...])

Log a summary of a list with optional debug preview.

log_section_header(logger, title[, char])

Log a section header for better visual separation.

log_subsection(logger, title)

Log a subsection for grouping related information.

setup_logging([log_level, log_file, use_colors])

Configure logging with improved formatting.

Classes

ColoredFormatter([fmt, use_colors])

Custom formatter with colors for different log levels.

class photon_mosaic_pipeline.logging_config.ColoredFormatter(fmt=None, use_colors=True)[source]#

Custom formatter with colors for different log levels.

Methods

format(record)

Format the specified record as text.

COLORS = {'CRITICAL': '\x1b[35m', 'DEBUG': '\x1b[36m', 'ERROR': '\x1b[31m', 'INFO': '\x1b[32m', 'WARNING': '\x1b[33m'}#
RESET = '\x1b[0m'#
BOLD = '\x1b[1m'#
format(record)[source]#

Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

photon_mosaic_pipeline.logging_config.ensure_dir(path, mode=493, parents=True, exist_ok=True)[source]#

Create a directory (Path or str) with optional permission setting.

Parameters:
  • path (str | Path) – Directory to create.

  • mode (int | None) – POSIX permission bits to set on the directory (e.g. 0o755). If None, permission change is skipped.

  • parents (bool) – Whether to create parent directories.

  • exist_ok (bool) – Whether to ignore if the directory already exists.

Returns:

The Path object for the created directory.

Return type:

Path

photon_mosaic_pipeline.logging_config.setup_logging(log_level='INFO', log_file=None, use_colors=True)[source]#

Configure logging with improved formatting.

This function is safe to call multiple times. If logging handlers are already configured (e.g., by the CLI), it will preserve them and only update the log level. This allows the Snakefile to adjust verbosity without losing the file handler set up by the CLI.

Parameters:
  • log_level (str) – Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)

  • log_file (Path, optional) – Path to log file for file handler. Only used if no handlers exist yet.

  • use_colors (bool) – Whether to use colored output for console. Only used if no handlers exist yet.

Returns:

logger – Configured root logger

Return type:

logging.Logger

Notes

When called from the Snakefile after the CLI has already configured logging, this function will: - Keep the existing file handler (so Snakemake logs go to the same file) - Keep the existing console handler - Update the log level on both root logger and console handler - Ignore the log_file and use_colors parameters

photon_mosaic_pipeline.logging_config.log_section_header(logger, title, char='=')[source]#

Log a section header for better visual separation.

photon_mosaic_pipeline.logging_config.log_subsection(logger, title)[source]#

Log a subsection for grouping related information.

photon_mosaic_pipeline.logging_config.log_list_summary(logger, items, item_type, preview_count=5)[source]#

Log a summary of a list with optional debug preview.

Parameters:
  • logger (logging.Logger) – Logger instance to use

  • items (list) – List of items to summarize

  • item_type (str) – Description of the items (e.g., “Preprocessing targets”, “Suite2p targets”)

  • preview_count (int) – Number of items to show in debug mode (default: 5)