Logger¶
- class pathsim.utils.logger.LoggerManager[source]¶
Bases:
objectSingleton class for centralized logging configuration in PathSim.
Provides a unified interface for creating and configuring loggers throughout the PathSim package. All loggers follow a hierarchical naming scheme under the ‘pathsim’ root logger, allowing fine-grained control over logging levels and output destinations.
The singleton pattern ensures that logging configuration is consistent across the entire application, with all modules sharing the same handler setup and formatting rules.
Examples
# Get the singleton instance and configure logging from pathsim.utils.logger import LoggerManager mgr = LoggerManager() mgr.configure( enabled=True, output="simulation.log", # File path or None for stdout level=logging.INFO ) # Get a logger for a specific module logger = mgr.get_logger("simulation") logger.info("Simulation started") # Set different log levels for different modules mgr.set_level(logging.DEBUG, "progress") mgr.set_level(logging.WARNING, "analysis")
Notes
The LoggerManager uses a hierarchical logger structure:
pathsim (root) - pathsim.simulation - pathsim.progress
pathsim.progress.TRANSIENT
pathsim.progress.STEADYSTATE
pathsim.analysis - pathsim.analysis.timer - pathsim.analysis.profiler
This hierarchy allows you to control logging at different granularities: set the level on ‘pathsim’ to affect all loggers, or set it on ‘pathsim.progress’ to affect only progress tracking loggers.
- configure(enabled=True, output=None, level=20, format=None, date_format=None)[source]¶
Configure the root PathSim logger and all child loggers.
This method sets up the logging system with the specified parameters. All loggers created via get_logger() will inherit this configuration. Can be called multiple times to reconfigure logging.
- Parameters:
enabled (bool, optional) – Whether logging is enabled. If False, all logging is disabled. Defaults to True.
output (str or None, optional) – Output destination for logs. If a string, interpreted as a file path and logs are written to that file. If None, logs are written to stdout. Defaults to None (stdout).
level (int, optional) – Logging level (e.g., logging.DEBUG, logging.INFO, logging.WARNING). Defaults to logging.INFO.
format (str or None, optional) – Log message format string. If None, uses default format. Defaults to “%(asctime)s - %(levelname)s - %(message)s”.
date_format (str or None, optional) – Date format string for timestamps (e.g., ‘%H:%M:%S’). If None, uses default format. Defaults to None.
Examples
mgr = LoggerManager() # Log to stdout with INFO level mgr.configure(enabled=True) # Log to file with DEBUG level mgr.configure(enabled=True, output="debug.log", level=logging.DEBUG) # Disable all logging mgr.configure(enabled=False) # Custom format with time only mgr.configure( enabled=True, format="%(asctime)s - %(message)s", date_format='%H:%M:%S' )
- get_logger(name)[source]¶
Get or create a logger with PathSim hierarchy.
Returns a logger under the ‘pathsim’ namespace. The logger inherits configuration from the root logger but can be individually configured via set_level().
- Parameters:
name (str) – Name of the logger, will be prefixed with ‘pathsim.’ to create hierarchical logger (e.g., ‘simulation’ -> ‘pathsim.simulation’).
- Returns:
Logger instance with the specified name under pathsim hierarchy.
- Return type:
Examples
mgr = LoggerManager() mgr.configure(enabled=True) # Get logger for simulation module sim_logger = mgr.get_logger("simulation") sim_logger.info("Starting simulation") # Get logger for progress tracking progress_logger = mgr.get_logger("progress.TRANSIENT") progress_logger.debug("Progress update")
- set_level(level, module=None)[source]¶
Set logging level globally or for a specific module.
Allows fine-grained control over logging verbosity. Can set the level for all loggers (when module=None) or for a specific logger in the hierarchy.
- Parameters:
level (int) – Logging level (e.g., logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, logging.CRITICAL).
module (str or None, optional) – Module name to set level for (e.g., ‘progress’, ‘analysis.timer’). If None, sets level for the root pathsim logger, affecting all child loggers that don’t have their own level set. Defaults to None.
Examples
mgr = LoggerManager() mgr.configure(enabled=True) # Set global level to INFO mgr.set_level(logging.INFO) # Set debug level for progress tracking only mgr.set_level(logging.DEBUG, "progress") # Quiet analysis logs mgr.set_level(logging.WARNING, "analysis")