Logging
Logging module, a wrapper around structlog library.
- class peak.tools.logging.LogHandler(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Enumeration of log handlers to be used in logging.
Each enum member corresponds to a specific handler defined in the logging module. This enum provides a convenient way to specify handlers when configuring loggers.
- CONSOLE
Represents a console handler, intended for displaying logs in the console.
- FILE
Represents a file handler, intended for writing logs to a file.
- class peak.tools.logging.LogLevel(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Enumeration of log levels to be used in logging.
Each enum member corresponds to a specific log level defined in the logging module. The enum provides a convenient way to specify log levels when configuring loggers.
- DEBUG
Debug log level. Intended for detailed debugging information.
- INFO
Info log level. Used for general information about program execution.
- WARN
Warning log level. Indicates potential issues or unexpected behavior.
- ERROR
Error log level. Indicates errors that do not prevent program execution.
- CRITICAL
Critical log level. Indicates severe errors that might lead to program failure.
- class peak.tools.logging.PeakLogger(logger)
Wrapper class for logging with various log levels.
- Parameters:
logger (Any) –
- bind(context=None, **kwargs)
Bind contextual information to the logger, enriching log messages.
This method allows attaching context data to the logger, such as additional information or system details, to provide more context in log messages.
- Parameters:
context (Union[dict[str, Any], None]) – A dictionary or None for contextual information.
**kwargs – Additional key-value pairs to enhance context.
- Return type:
None
- critical(message, *args, **kwargs)
Log a CRITICAL level message.
- Parameters:
message (str) – The log message.
*args – Additional positional arguments to be passed to the logger.
**kwargs – Additional keyword arguments to be passed to the logger.
- Return type:
None
- debug(message, *args, **kwargs)
Log a DEBUG level message.
- Parameters:
message (str) – The log message.
*args – Additional positional arguments to be passed to the logger.
**kwargs – Additional keyword arguments to be passed to the logger.
- Return type:
None
- error(message, *args, **kwargs)
Log an ERROR level message.
- Parameters:
message (str) – The log message.
*args – Additional positional arguments to be passed to the logger.
**kwargs – Additional keyword arguments to be passed to the logger.
- Return type:
None
- exception(message, *args, **kwargs)
Log an ERROR level message with exception info.
- Parameters:
message (str) – The log message.
*args – Additional positional arguments to be passed to the logger.
**kwargs – Additional keyword arguments to be passed to the logger.
- Return type:
None
- info(message, *args, **kwargs)
Log an INFO level message.
- Parameters:
message (str) – The log message.
*args – Additional positional arguments to be passed to the logger.
**kwargs – Additional keyword arguments to be passed to the logger.
- Return type:
None
- set_log_level(level)
Set the log level of the root logger.
- Parameters:
level (LogLevel) – Log level to set.
- Return type:
None
- unbind(keys)
Unbind specified keys from the logger’s context.
- Parameters:
keys (list[str]) – List of keys to unbind.
- Return type:
None
- warn(message, *args, **kwargs)
Log a WARNING level message.
- Parameters:
message (str) – The log message.
*args – Additional positional arguments to be passed to the logger.
**kwargs – Additional keyword arguments to be passed to the logger.
- Return type:
None
- peak.tools.logging.get_logger(name=None, level=LogLevel.INFO, pretty_print=None, disable_masking=None, handlers=None, file_name=None)
Return a logger with the specified settings.
- Parameters:
name (Optional[str], optional) – Name of the logger. Defaults to None.
level (LogLevel) – Log level. Defaults to LogLevel.INFO.
pretty_print (Optional[bool], optional) – Whether to enable pretty printing for JSON format. Defaults to False.
disable_masking (Optional[bool], optional) – Whether to disable masking of sensetive data. Defaults to False.
handlers (Optional[List[Handlers]], optional) – List of log handlers (CONSOLE, FILE). Defaults to CONSOLE.
file_name (Optional[str], optional) – Filename for FILE handler. Required if FILE handler is used. Defaults to None.
- Returns:
A logger instance configured with the specified settings.
- Return type:
- Raises:
ValueError – If the file_name is not provided for FILE handler.