pyechonext.logging package¶
Submodules¶
pyechonext.logging.logger module¶
- class pyechonext.logging.logger.LoggerManager[source]¶
Bases:
object
Manager for configuring and handling logging in the application.
This class is responsible for creating and managing instances of loggers, allowing users to configure log levels, handlers, and formats easily. Each LoggerManager instance can set up a dedicated logger for a particular usage context.
- logger¶
The logger instance configured for the library.
- Type:
logging.Logger
- handlers_configured¶
Flag indicating if the handlers have been set up.
- Type:
bool
- __init__()[source]¶
Initializes the LoggerManager instance with a logger and default configuration.
The constructor sets up a logger for the “pyechonext” namespace and applies the default logging configuration.
- add_handler(handler: Handler, formatter: Formatter)[source]¶
Adds a new handler to the logger with a specified formatter.
This method attaches a logging handler (either stream or file) to the logger and sets its message format.
- Parameters:
handler (logging.Handler) – The logging handler to add (e.g., StreamHandler).
formatter (logging.Formatter) – The formatter to set for the handler.
- clear_handlers()[source]¶
Removes all existing handlers from the logger.
This method ensures that the logger starts with a clean slate before new handlers are added, preventing duplicate log messages and improving configuration consistency.
- configure_logging(level: int = 20, stream_handler: bool = True, file_handler: str | None = None, formatter: Formatter | None = None)[source]¶
Configures the logging settings for the logger.
This method sets the log level, specifies if a stream handler should be added, and optionally allows for a file handler and a specific message format.
- Parameters:
level (int) – The logging level to set for the logger (default: logging.INFO).
stream_handler (bool) – Flag to indicate if output to stdout should occur (default: True).
file_handler (Optional[str]) – Path to a file where logs will be written (default: None).
formatter (Optional[logging.Formatter]) – A formatter instance for custom log message formatting (default: None).
- default_formatter() Formatter [source]¶
Returns the default log message formatter.
The default formatter outputs the log messages with the format: ‘timestamp - logger name - log level - message’.
- Returns:
The default formatter for log messages.
- Return type:
logging.Formatter
- pyechonext.logging.logger.create_logger(level: int = 20, stream_handler: bool = True, file_handler: str | None = None, formatter: Formatter | None = None) Logger [source]¶
Creates and configures a new logger instance.
This function instantiates a LoggerManager, applies the specified logging configuration, and returns the logger for further use.
- Parameters:
level (int) – The logging level to set for the logger (default: logging.INFO).
stream_handler (bool) – Flag to indicate if output to stdout should occur (default: True).
file_handler (Optional[str]) – Path to a file where logs will be written (default: None).
formatter (Optional[logging.Formatter]) – A formatter instance for custom log message formatting (default: None).
- Returns:
The configured logger instance.
- Return type:
logging.Logger