thinlog.filters package#

Log filters for whitelisting, blocklisting, and conditional attribute assignment.

class thinlog.filters.AssignerFilter(assignments: dict[str, Any], **kwargs: Any)[source]#

Bases: WhitelistFilter

Assign attributes to matching records without blocking any.

Extends WhitelistFilter – if a record matches the whitelist criteria, the assignments dict is applied to the record as attributes. The filter always returns True so no records are dropped.

Parameters:

assignments – Mapping of attribute names to values that will be set on matching records via setattr().

filter(record: LogRecord) bool[source]#

Apply assignments if the record matches, then always return True.

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

Bases: Filter

Block records whose name, message, or attributes match a blocklist.

This is the inverse of WhitelistFilter. Any record that matches is rejected; all others pass through.

Parameters:
  • by_name – Logger names to block.

  • by_msg – Messages to block.

  • by_attr – Mapping of attribute names to values that trigger blocking. Use "_any_" to block on any value for a given attribute.

filter(record: LogRecord) bool[source]#

Return False if the record matches any blocklist criterion.

class thinlog.filters.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.

Submodules#