Logger¶
glpi_utils.logger.SensitiveFilter
¶
Bases: Filter
Filter that scrubs sensitive data from log records before emission.
Intercepts record.args (both dict and tuple forms) and
replaces sensitive field values with :func:mask_secret.
Usage::
import logging
from glpi_utils.logger import SensitiveFilter
handler = logging.StreamHandler()
handler.addFilter(SensitiveFilter())
logging.getLogger("glpi_utils").addHandler(handler)
logging.getLogger("glpi_utils").setLevel(logging.DEBUG)
Source code in glpi_utils/logger.py
glpi_utils.logger.EmptyHandler
¶
Bases: Handler
A no-op handler so the library never emits output by default.
Attach it to the glpi_utils logger to suppress the
"No handlers could be found" warning while still allowing the caller
to add their own handlers.
Source code in glpi_utils/logger.py
glpi_utils.logger.mask_secret
¶
Replace the middle portion of value with ****.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The raw secret string. |
required |
show_len
|
int
|
Number of characters to reveal on each side. If the string is too short relative to the mask length, returns the mask only. |
_SHOW_LEN
|
Returns:
| Type | Description |
|---|---|
str
|
Masked string, e.g. |
Source code in glpi_utils/logger.py
glpi_utils.logger.hide_sensitive
¶
Recursively mask sensitive values inside data.
Accepts dict, list, or scalar values. Non-sensitive values are
returned unchanged. Dicts and lists are deep-copied (shallow) so the
original object is never mutated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
Input data — typically the |
required |
_depth
|
int
|
Internal recursion guard (max depth 10). |
0
|
Returns:
| Type | Description |
|---|---|
Any
|
Data with sensitive field values replaced by the mask. |