pcdsutils.log.LogWarningLevelFilter
- class pcdsutils.log.LogWarningLevelFilter(level: str | int = 10, only_duplicates: bool = True)[source]
Filter to decrease the log level of repeat warnings.
Once installed, the first instance of a “warnings.warn” converted to a log message will be at “WARNING” level, while subsequent repeats of the same warning will be at “DEBUG” level.
When running a normal program, typically the warnings module will handle warning filtering for you as the default behavior, making every unique warning only appear once.
When running in ipython, the warnings cache is reset prior to running every command, so it’s possible to see repeat warnings during or after each command. This is a annoying. The filter here allows us to adjust the level of the repeat messages to avoid cluttering the user’s view, or to remove them entirely.
This filter incorporates a resettable counter that will count the number of demoted log messages.
- Parameters:
- levelstr or int, optional
The log level or name of the log level to reduce duplicate log messages to. Defaults to logging.DEBUG.
- 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.
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
WarningRecordInfoshould_demote(*args, **kwargs)All warnings should be demoted (only_duplicates=True)
uninstall()Convenience method for removing this filter.
reset_counter
- __init__(level: str | int = 10, only_duplicates: bool = True)
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(*args, **kwargs)All warnings should be demoted (only_duplicates=True)
uninstall()Convenience method for removing this filter.
Attributes
default_loggercachelevelnolevelnameonly_duplicatescounter