pcdsutils.log.DemotionFilter
- class pcdsutils.log.DemotionFilter(level: str | int = 10, only_duplicates: bool = True)[source]
Filter parent class for demoting log records.
Supports:
Demoting duplicate records when paired with a hashable dataclass
Optionally demoting all records that match a specification
A counter that tracks how many records have been demoted
Child classes can/should override the following methods:
should_demote (without super)
__init__ (optional, and with super)
Child classes should override the following attributes:
record_dataclass (inherit and customize from RecordInfo)
default_logger (logging.Logger instance)
cache (just the type annotation)
- Parameters:
- level: str or int, optional
The level to demote matching messages to. Defaults to logging.DEBUG, but this behavior can be overridden in the child class.
- only_duplicates: bool, optional
If True, the default, only demote duplicated log messages. If False, demote all log messages that pass through should_demote. This must be False if no record_dataclass is provided.
- Attributes:
- default_logger
Methods
filter(record)Demote the log message if appropriate, return True to let it pass.
install([level, only_duplicates, logger])Create and apply the DemotionFilter to a specific logger, or the default logger.
install_self([logger])Convenience method for adding this filter to a logger.
record_dataclassalias of
RecordInfoshould_demote(record, info)Return True if we should demote the record, False otherwise.
uninstall()Convenience method for removing this filter.
reset_counter
- __init__(level: str | int = 10, only_duplicates: bool = True)[source]
Initialize a filter.
Initialize with the name of the logger which, together with its children, will have its events allowed through the filter. If no name is specified, allow every event.
Methods
__init__([level, only_duplicates])Initialize a filter.
filter(record)Demote the log message if appropriate, return True to let it pass.
install([level, only_duplicates, logger])Create and apply the DemotionFilter to a specific logger, or the default logger.
install_self([logger])Convenience method for adding this filter to a logger.
reset_counter()should_demote(record, info)Return True if we should demote the record, False otherwise.
uninstall()Convenience method for removing this filter.
Attributes
default_loggerlevelnolevelnameonly_duplicatescachecounter