config_logging
Logging a configuration both as it was passed and as it was parsed.
A configuration reaches the code that acts on it through several layers: YAML or JSON as written, a schema that fills in defaults, and objects whose constructors derive further settings from those. When a site behaves in a way its configuration does not seem to ask for, the question is which of those layers changed what. Logging the input and the result side by side answers it from the log alone.
Both views go through redact_for_log, which hides any value whose key names a
credential and masks a password embedded in a URL. Logging never raises: a view
that cannot be built or serialised is named in the log line instead, so a
diagnostic cannot be what stops a pod starting or a run going ahead.
Module
Functions
is_secret_name
def is_secret_name(name: str) ‑> bool:Return whether a value held under name should stay out of the logs.
Arguments
name: The key or argument name.
Returns
Whether the name contains any of SECRET_NAME_MARKERS, ignoring case.
log_config_views
def log_config_views( label: str, *, passed: object, parsed: object, log: logging.Logger,) ‑> None:Log label's config as passed and as parsed, one INFO line each.
Either view may be a zero-argument callable, which is called here, inside the same guard as the serialisation, so a view that is costly or may fail to build is only built for the log and cannot raise out of it.
Arguments
label: What the config is, e.g."Pod config".passed: The config as it was given.parsed: The config as the code will act on it.log: The logger to write to.
redact_for_log
def redact_for_log(value: object) ‑> object:Return a JSON-safe copy of value with its secrets hidden.
Mappings, sequences, sets, dataclasses and pydantic models are walked; a
value held under a secret-named key becomes "<redacted>", and inside a
string (or a repr) a URL's password and the value of a credential-named
field (e.g. ?password= or ODBC's PWD=) become ***. Paths, dates and
enums become their plain JSON form; anything else json cannot encode
becomes its repr.
Arguments
value: The view to make safe.
Returns The safe copy.