Logger
Logger module.
This module provides a pre-configured logger for the Perseo framework with support for custom log levels (TRACE, FAIL, SUCCESS), Rich-formatted console output, and plain file logging.
The logger is designed to be flexible and easy to use, with sensible defaults for console output and optional file logging. By default, it uses Rich handlers to provide visually appealing and informative log messages in the console, while file output is plain text for compatibility.
This module is the primary way to log throughout the Perseo ecosystem.
To initialize the logger with sensible defaults, use the initialize function.
Otherwise, the logger has a null handler by default and it will be silent until configured.
For advanced usage, you can access the underlying logger instance via the get_logger() function
and customize handlers, formatters, or log levels as needed.
Custom Log Levels
- TRACE (5): hyper-detailed debugging, below DEBUG.
- FAIL (21): indicates a failed validation or test.
- SUCCESS (22): indicates a successful validation or test.
Console log default output streams
The logger separates output streams:
- TRACE, DEBUG, INFO, WARNING, FAIL, SUCCESS -> stdout
- ERROR, CRITICAL -> stderr
Examples
Basic usage:
import logging
from perseo_core import logger
logger.initialize(log_file="perseo.log", log_level=logging.INFO)
logger.info("Processing started")
logger.error("An error occurred")
logger.fail("Operation failed")
logger.success("Operation completed")
Bypass initialization and add a different file handler:
Note
The logger is initialized with both stdout and stderr Rich handlers by default.
To customize handlers or log levels, access the underlying logger via get_logger().
Attributes
FILE_FORMAT
module-attribute
Classes
StdOutRichHandler
StdErrRichHandler
PlainFileFormatter
Bases: Formatter
Plain text formatter for file output (no Rich markup).
CustomFileHandler
Bases: FileHandler
File handler with plain text formatting and UTF-8 encoding.
Functions:
initialize
Initialize the Perseo logger with Rich console and optional file handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log_file
|
str or Path - like
|
If provided, a file handler will be added to write plain-text logs to this path. Parent directories are created automatically if they do not exist. |
None
|
log_level
|
int
|
Logging level to set for the logger (default is |
DEBUG
|
set_level
Set the logging level for the Perseo logger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
int
|
One of |
required |