log_utils¶
log_utils ¶
ExtendedLogger ¶
Bases: Logger
A logging.Logger with an added trace() method, for the custom TRACE level (TRACE_LEVEL_NUM, below DEBUG).
Source code in source/src/imarina_load_researchers/core/log_utils.py
trace ¶
Logs message at the custom TRACE level (below DEBUG).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message | str | The message to log, with | required |
*args | Any | Values for | () |
**kwargs | Any | Forwarded to the underlying | {} |
Source code in source/src/imarina_load_researchers/core/log_utils.py
SecretsFilter ¶
Bases: Filter
A logging.Filter that redacts known secret values out of log records before they reach a handler.
Source code in source/src/imarina_load_researchers/core/log_utils.py
__init__ ¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
secrets | list[str] | None | Secret values to redact from every log record's message, or | required |
Source code in source/src/imarina_load_researchers/core/log_utils.py
filter ¶
Replaces any occurrence of a known secret in record.msg with *****.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record | LogRecord | The record to redact, mutated in place. | required |
Returns:
| Name | Type | Description |
|---|---|---|
bool | bool | Always |
Source code in source/src/imarina_load_researchers/core/log_utils.py
setup_logging ¶
setup_logging(level: int | None, log_file: str | Path | None = None, secrets: list[str] | None = None) -> None
Configures the root logger with a Rich console handler and, optionally, a file handler - both filtered through SecretsFilter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level | int | None | stdlib | required |
log_file | str | Path | None | If given, also log to this file (parent directories are created as needed). | None |
secrets | list[str] | None | Secret values to redact from every log record via | None |
Source code in source/src/imarina_load_researchers/core/log_utils.py
obfuscate_text ¶
Masks a piece of sensitive text (e.g. a secret) for safe logging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text | str | None | The value to mask. | required |
Returns:
| Name | Type | Description |
|---|---|---|
str | str |
|
Source code in source/src/imarina_load_researchers/core/log_utils.py
get_logger ¶
process_log_flags ¶
process_log_flags(very_verbose: bool, verbose: bool, quiet: bool, very_quiet: bool) -> tuple[LogLevel | None, bool]
Resolves the CLI's mutually-exclusive verbosity flags into a LogLevel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
very_verbose | bool |
| required |
verbose | bool |
| required |
quiet | bool |
| required |
very_quiet | bool |
| required |
Returns:
| Type | Description |
|---|---|
tuple[LogLevel | None, bool] | tuple[LogLevel | None, bool]: The resolved |
Source code in source/src/imarina_load_researchers/core/log_utils.py
configure_logging_from_settings ¶
configure_logging_from_settings(level: LogLevel | None = None, log_file: Path = DEFAULT_LOG_PATH, secrets: list[str] | None = None) -> None
Sets up logging from a resolved LogLevel, defaulting the level if unset.
Thin wrapper around setup_logging that converts a logical LogLevel into the stdlib level it expects; this is the entry point called from cli_global_callback for every CLI invocation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level | LogLevel | None | The logical log level to use; defaults to | None |
log_file | Path | Path to also log to, forwarded to | DEFAULT_LOG_PATH |
secrets | list[str] | None | Secret values to redact from log output, forwarded to | None |