thinlog.filters.whitelist module

thinlog.filters.whitelist module#

Whitelist filter – allow log records that match specific criteria.

class thinlog.filters.whitelist.WhitelistFilter(by_name: list[str] | None = None, by_msg: list[str] | None = None, by_attr: dict[str, Any] | None = None, **kwargs: Any)[source]#

Bases: Filter

Allow records whose name, message, or attributes match a whitelist.

Records are checked against three criteria (any match is sufficient):

  • by_name – the record’s logger name.

  • by_msg – the record’s message (also checked inside JSON-encoded messages).

  • by_attr – arbitrary record attributes; use the special value "_any_" to match any value for a given attribute.

Parameters:
  • by_name – Logger names to allow.

  • by_msg – Messages to allow.

  • by_attr – Mapping of attribute names to expected values.

filter(record: LogRecord) bool[source]#

Return True if the record matches any whitelist criterion.