Logging¶
pyclif ships a Rich-enhanced logging system with a custom TRACE level (5), automatic
secrets masking, and rotating file handler support.
get_logger¶
Main factory. Returns a logger pre-configured with Rich formatting.
pyclif.get_logger(name=None)
¶
Factory function for creating loggers with Rich capabilities.
This function uses the global configuration system to provide loggers that automatically benefit from Rich enhancements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Logger name (optional). |
None
|
Returns:
| Type | Description |
|---|---|
SupportsTraceLogger
|
Logger configured with Rich capabilities. |
Source code in src/pyclif/core/log/__init__.py
get_configured_logger¶
Returns a logger with full configuration applied (handlers, level, masker).
pyclif.get_configured_logger(name=None)
¶
Get a logger that automatically benefits from global Rich configuration.
This function simply retrieves a standard logger that automatically inherits the global Rich configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Logger name (optional). |
None
|
Returns:
| Type | Description |
|---|---|
SupportsTraceLogger
|
Logger automatically configured with Rich capabilities. |
Source code in src/pyclif/core/log/config.py
configure_rich_logging¶
Low-level setup function. Called internally by get_configured_logger.
pyclif.configure_rich_logging(use_rich=True, rich_tracebacks=True, enable_secrets_filter=True, force_reconfigure=False)
¶
Configure the Rich logging system once and centrally.
This function sets up the entire logging system in one place: - Global configuration via extraBasicConfig - Adds trace() method to all Python loggers - Prevents multiple configurations with built-in checks
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
use_rich
|
bool
|
Enable Rich logging capabilities. |
True
|
rich_tracebacks
|
bool
|
Enable Rich tracebacks for exceptions. |
True
|
enable_secrets_filter
|
bool
|
Enable automatic secrets filtering. |
True
|
force_reconfigure
|
bool
|
Force reconfiguration even if already configured. |
False
|
Source code in src/pyclif/core/log/config.py
add_trace_method¶
Patches a logger instance with a .trace() method at level 5.
pyclif.add_trace_method(logger_class)
¶
Add a trace method to a logger class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger_class
|
type
|
Logger class to extend. |
required |
Returns:
| Type | Description |
|---|---|
type
|
The updated logger class. |
Source code in src/pyclif/core/log/levels.py
SecretsMasker¶
Log filter that redacts sensitive values from log records.
pyclif.SecretsMasker
¶
Bases: Filter
Redact secrets from logs
Source code in src/pyclif/core/log/filters.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
__init__()
¶
filter(record)
¶
Filter a log record by redacting sensitive values.
Checks whether the record was already processed to avoid duplicate redaction. If not processed, applies redaction to all record fields containing sensitive data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
LogRecord
|
The log record to filter. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the record was successfully filtered or already processed, |
bool
|
False if no replacer is configured. |
Source code in src/pyclif/core/log/filters.py
redact(item, name=None)
¶
Redact sensitive information from the given input data.
Processes the provided item and optionally uses the name for context during redaction to securely obfuscate sensitive fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Any
|
The data object to be redacted. |
required |
name
|
str | None
|
An optional name providing context for the redaction process. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The redacted version of the input data. |
Source code in src/pyclif/core/log/filters.py
RichExtraFormatter / RichExtraStreamHandler¶
Rich-aware formatter and stream handler. Wired up automatically by configure_rich_logging.
pyclif.RichExtraFormatter
¶
Bases: ExtraFormatter
Enhanced ExtraFormatter with Rich text capabilities and TRACE level support.
Extends click-extra's ExtraFormatter to support Rich markup and custom TRACE level while preserving a click-extra's colorization system.
Source code in src/pyclif/core/log/formatters.py
formatMessage(record)
¶
Enhanced formatting with Rich support and TRACE level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
LogRecord
|
LogRecord to format. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted message string. |
Source code in src/pyclif/core/log/formatters.py
pyclif.RichExtraStreamHandler
¶
Bases: ExtraStreamHandler
Enhanced ExtraStreamHandler with Rich support and built-in security filtering.
Extends click-extra's ExtraStreamHandler to use Rich for beautiful logging while maintaining compatibility with click.echo() and color support. Automatically includes SecretsMasker for sensitive data protection.
Source code in src/pyclif/core/log/handlers.py
__init__(stream=None, rich_tracebacks=True, enable_secrets_filter=True, **kwargs)
¶
Initialize the Rich Extra Stream Handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stream
|
TextIOBase | None
|
Output stream (defaults to sys.stderr). |
None
|
rich_tracebacks
|
bool
|
Enable Rich tracebacks. |
True
|
enable_secrets_filter
|
bool
|
Enable automatic secrets filtering. |
True
|
**kwargs
|
Any
|
Additional keyword arguments passed to RichHandler. |
{}
|
Source code in src/pyclif/core/log/handlers.py
emit(record)
¶
Use Rich handler for enhanced output while maintaining click-extra compatibility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
LogRecord
|
LogRecord to emit. |
required |