Logger
Logger
A utility class for configuring and managing loggers in the application.
It configures logging with both file and console output, using a consistent format across all loggers.
configure_logger
classmethod
configure_logger(level: str = 'INFO', filename: str = 'mindwave.log', filemode: str = 'w', console_output: bool = True, file_output: bool = True) -> None
Configures the logger with the specified level and output options.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
level
|
str
|
The logging level to use. Possible values are "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL". |
'INFO'
|
filename
|
str
|
The name of the file to write logs to. |
'mindwave.log'
|
filemode
|
str
|
The mode to open the log file in. |
'w'
|
console_output
|
bool
|
Whether to enable logging to console. |
True
|
file_output
|
bool
|
Whether to enable logging to file. |
True
|
Raises:
Type | Description |
---|---|
ValueError
|
If both console_output and file_output are False. |
Examples:
>>> # Basic usage with default settings (both console and file logging)
>>> MyClass.configure_logger()
>>> # Debug level logging to console only
>>> MyClass.configure_logger(
... level="DEBUG",
... console_output=True,
... file_output=False
... )
>>> # Error level logging to specific file in append mode
>>> MyClass.configure_logger(
... level="ERROR",
... filename="errors.log",
... filemode="a",
... console_output=False,
... file_output=True
... )
>>> # Multiple output logging with custom configuration
>>> MyClass.configure_logger(
... level="INFO",
... filename="application.log",
... filemode="w",
... console_output=True,
... file_output=True
... )
The resulting log entries will look like: 2024-01-12 10:30:45,123 [INFO] my_module::MyClass.my_function - Log message here
Source code in mindwave/utils/logger.py
get_logger
classmethod
Gets a named logger instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
A string specifying the logger name, typically the module or component name. |
required |
Returns:
Type | Description |
---|---|
Logger
|
logging.Logger: A configured logger instance with the specified name. |
Examples: