Update LoggerFilter to lazy init rules
from logging import Filter, Logger, LogRecord
from typing import Dict, List
+from plextraktsync.decorators.cached_property import cached_property
+
@dataclass
class FilterRule:
@@ -20,12 +22,16 @@ class LoggerFilter(Filter):
def __init__(self, rules: List[Dict], logger: Logger):
super().__init__()
self.logger = logger
- self.rules = self.load_rules(rules or [])
- self.nrules = len(self.rules)
+ self._rules = rules or []
+
+ @cached_property
+ def nrules(self):
+ return len(self.rules)
- def load_rules(self, rules: List[Dict]):
+ @cached_property
+ def rules(self):
filters = []
- for rule in rules:
+ for rule in self._rules:
try:
f = FilterRule(**rule)
except TypeError as e:
