Logging#
Loguru-based logging with console and rotating file handlers.
Use get_logger() in every module.
thesis.core.logging#
Logging system for the thesis framework.
This module provides a centralized logging configuration using loguru. It supports both console and file output with rotation, colored output, and structured logging for medical imaging processing pipelines.
Example
>>> from thesis.core.logging import get_logger
>>> logger = get_logger(__name__)
>>> logger.info("Processing started")
>>> logger.debug(f"Image shape: {shape}")
- thesis.core.logging.get_logger(name=None)[source]#
Get a logger instance for a module.
This function returns the global loguru logger with context about the calling module. The logger is automatically configured on first use.
- Parameters:
name (
Optional[str]) – Name of the module/component (typically __name__)- Return type:
- Returns:
Logger instance with module context
Example
>>> logger = get_logger(__name__) >>> logger.info("Processing image")
- thesis.core.logging.setup_logging(log_dir=None, log_level='INFO', console_output=True, file_output=True, rotation='10 MB', retention='7 days', compression='zip')[source]#
Configure the logging system for the application.
- Parameters:
log_dir (
Union[str,Path,None]) – Directory for log files. If None, uses ‘./logs’log_level (
str) – Minimum log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)console_output (
bool) – Whether to output logs to consolefile_output (
bool) – Whether to output logs to filerotation (
str) – When to rotate log files (size or time-based)retention (
str) – How long to keep old log filescompression (
str) – Compression format for rotated logs
- Return type:
Example
>>> setup_logging(log_dir="./logs", log_level="DEBUG") >>> logger.info("Logging configured")
- thesis.core.logging.reset_logging()[source]#
Reset the logging system (primarily for testing).
Removes all handlers and resets the initialization flag.
- Return type:
- thesis.core.logging.set_console_level(level)[source]#
Change the console handler’s minimum log level at runtime.
This is used by the CLI output system to suppress verbose loguru messages when the user has not requested
-v/--verbose. File handlers are unaffected so the full log is always available.
- class thesis.core.logging.InterceptHandler[source]#
Bases:
HandlerIntercepts stdlib logging records and forwards them to loguru.
Install once via logging.basicConfig(handlers=[InterceptHandler()], level=0, force=True) to route all third-party library logs (e.g. Nipype, FSL wrappers) through loguru’s formatting.
- thesis.core.logging.suppress_nipype_native_logging()[source]#
Remove nipype’s own StreamHandlers to prevent duplicate log output.
Nipype attaches StreamHandlers directly to named loggers (nipype.workflow, nipype.pipeline.*, etc.) that output in nipype’s native format. Since the root InterceptHandler already routes those records to loguru, the native handlers produce duplicate lines. Call this once after nipype is imported.
- Return type:
thesis.core.logging.handlers#
Custom log handlers for specialized logging needs.
This module provides custom handlers for specific logging scenarios in medical imaging pipelines, such as patient-specific logs, step logs, and performance tracking.
- class thesis.core.logging.handlers.InterceptHandler[source]#
Bases:
HandlerIntercepts stdlib logging records and forwards them to loguru.
Install once via logging.basicConfig(handlers=[InterceptHandler()], level=0, force=True) to route all third-party library logs (e.g. Nipype, FSL wrappers) through loguru’s formatting.
thesis.core.logging.formatters#
Log formatting utilities for the thesis framework.
Provides consistent formatting for console and file output with appropriate detail levels and coloring.