API Reference¶
class
sanitary.
Sanitizer
(
keys=()
, patterns=()
, replacement='********'
, message='#### WARNING: Message replaced due to sensitive information.'
)
Base class for sensitive data sanitizers.
Parameters
keys
(iterable of str, optional) — Collection of keys to sanitize. Will be normalized to lowercase.patterns
(iterable of pattern, optional) — Collection of regular expression patterns; will be compiled usingre.compile
.replacement
(Union(str, callable(str: str), callable(bytes: hashobjectprotocol)), optional) — A string or callable to be used to replace the value. A callable must either accept and return astr
value, or accept abytes
object and return an object compatible with thehashlib
function.message
(str, optional) — The text to replace the matching string patterns.
Methods
sanitize
(
data
)
(any) — Sanitize data by masking potentially sensitive information.
method
sanitize
(
data
)
Sanitize data by masking potentially sensitive information.
If an unknown data type is encountered, its string representation will be sanitized.
Parameters
data
(any) — The data to sanitize.
Returns (any)
The sanitized form of data.
class
sanitary.
StructlogSanitizer
(
keys=()
, patterns=()
, replacement='********'
, message='#### WARNING: Message replaced due to sensitive information.'
)
Bases
sanitary.Sanitizer
Structlog processor for cleaning up logging context by masking sensitive data.
Parameters
keys
(iterable of str, optional) — Collection of keys to sanitize. Will be normalized to lowercase.patterns
(iterable of pattern, optional) — Collection of regular expression patterns; will be compiled usingre.compile
.replacement
(Union(str, callable(str: str), callable(bytes: hashobjectprotocol)), optional) — A string or callable to be used to replace the value. A callable must either accept and return astr
value, or accept abytes
object and return an object compatible with thehashlib
function.message
(str, optional) — The text to replace the matching string patterns.
method
sanitize
(
data
)
Sanitize data by masking potentially sensitive information.
If an unknown data type is encountered, its string representation will be sanitized.
Parameters
data
(any) — The data to sanitize.
Returns (any)
The sanitized form of data.
method
__call__
(
logger
, name
, event_dict
)
Makes the sanitizer a callable, compatible with the Structlog processor API.
For details see https://www.structlog.org/en/stable/processors.html
Parameters
logger
(WrappedLogger) — The logger instance doing the logging.name
(str) — Name of the logging method, e.g.info
orwarning
.event_dict
(EventDict) — Current context, including modifications by other processors.
Returns (EventDict)
dict