core.logging¶
Sanitizing log filter that redacts sensitive payloads before they reach handlers.
SanitizingFilter is implemented as a dataclass-backed logging.Filter
with the same filtering behavior.
taskclf.core.logging
¶
Sanitizing log filter that redacts sensitive payloads before they reach handlers.
Prevents accidental leakage of raw window titles, keystrokes, clipboard content, URLs, and other PII through log output.
Also provides :func:setup_file_logging for persisting logs to a rotating
file under <TASKCLF_HOME>/logs/.
SanitizingFilter
dataclass
¶
Bases: Filter
A :class:logging.Filter that rewrites log records to strip sensitive data.
Attach to any logger or handler via :func:install_sanitizing_filter
to ensure sensitive key/value pairs never reach log output.
Source code in src/taskclf/core/logging.py
redact_message(message)
¶
Replace sensitive key=value or key: value pairs with redaction markers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Raw log message string. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Message with sensitive values replaced by |
Source code in src/taskclf/core/logging.py
install_sanitizing_filter(logger=None, *, handler_level=False)
¶
Attach a :class:SanitizingFilter to logger (or the root logger).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger
|
Logger | None
|
Target logger. Defaults to the root logger if |
None
|
handler_level
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
SanitizingFilter
|
The filter instance that was installed (useful for later removal). |
Source code in src/taskclf/core/logging.py
setup_file_logging(log_dir=None, *, max_bytes=5000000, backup_count=3)
¶
Attach a :class:~logging.handlers.RotatingFileHandler to the root logger.
The handler always logs at DEBUG level so that error context is
captured even when the console level is WARNING. A
:class:SanitizingFilter is applied so PII is never written to disk.
If a RotatingFileHandler targeting the same file is already
present on the root logger, this function is a no-op (idempotent).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log_dir
|
str | Path | None
|
Directory for the log file. Defaults to
|
None
|
max_bytes
|
int
|
Maximum size of a single log file before rotation. |
5000000
|
backup_count
|
int
|
Number of rotated backup files to keep. |
3
|
Returns:
| Type | Description |
|---|---|
RotatingFileHandler | None
|
The handler that was created, or |