11from __future__ import annotations
22
33import logging
4+ from copy import copy
45from typing import Any
56
67import annotated_logger
@@ -14,29 +15,23 @@ class AnnotatedFilter(logging.Filter):
1415 def __init__ (
1516 self ,
1617 annotations : Annotations | None = None ,
17- runtime_annotations : Annotations | None = None ,
1818 class_annotations : Annotations | None = None ,
1919 plugins : list [annotated_logger .BasePlugin ] | None = None ,
2020 ) -> None :
2121 """Store the annotations, attributes and plugins."""
2222 self .annotations = annotations or {}
2323 self .class_annotations = class_annotations or {}
24- self .runtime_annotations = runtime_annotations or {}
2524 self .plugins = plugins or [annotated_logger .BasePlugin ()]
2625
2726 # This allows plugins to determine what fields were added by the user
2827 # vs the ones native to the log record
2928 # TODO(crimsonknave): Make a test for this # noqa: TD003, FIX002
3029 self .base_attributes = logging .makeLogRecord ({}).__dict__ # pragma: no mutate
3130
32- def _all_annotations (self , record : logging . LogRecord ) -> Annotations :
31+ def _all_annotations (self ) -> Annotations :
3332 annotations = {}
34- # Using copy might be better, but, we don't want to add
35- # the runtime annotations to the stored annotations
36- annotations .update (self .class_annotations )
37- annotations .update (self .annotations )
38- for key , function in self .runtime_annotations .items ():
39- annotations [key ] = function (record )
33+ annotations .update (copy (self .class_annotations ))
34+ annotations .update (copy (self .annotations ))
4035 annotations ["annotated" ] = True
4136 return annotations
4237
@@ -48,7 +43,7 @@ def filter(self, record: logging.LogRecord) -> bool:
4843 sees it. Returning False from the filter method will stop the evaluation and
4944 the log record won't be emitted.
5045 """
51- record .__dict__ .update (self ._all_annotations (record ))
46+ record .__dict__ .update (self ._all_annotations ())
5247 for plugin in self .plugins :
5348 try :
5449 result = plugin .filter (record )
0 commit comments