@@ -57,7 +57,7 @@ def _match_by_action(self, action: str, condition_value: Any, context_value: Any
57
57
func = mapping_by_action .get (action , lambda a , b : False )
58
58
return func (context_value , condition_value )
59
59
except Exception as exc :
60
- self .loggerdebug (f"caught exception while matching action: action={ action } , exception={ str (exc )} " )
60
+ self .logger . debug (f"caught exception while matching action: action={ action } , exception={ str (exc )} " )
61
61
return False
62
62
63
63
def _evaluate_conditions (
@@ -68,7 +68,7 @@ def _evaluate_conditions(
68
68
conditions = cast (List [Dict ], rule .get (schema .CONDITIONS_KEY ))
69
69
70
70
if not conditions :
71
- self .loggerdebug (
71
+ self .logger . debug (
72
72
f"rule did not match, no conditions to match, rule_name={ rule_name } , rule_value={ rule_match_value } , "
73
73
f"name={ feature_name } "
74
74
)
@@ -80,13 +80,13 @@ def _evaluate_conditions(
80
80
cond_value = condition .get (schema .CONDITION_VALUE )
81
81
82
82
if not self ._match_by_action (action = cond_action , condition_value = cond_value , context_value = context_value ):
83
- self .loggerdebug (
83
+ self .logger . debug (
84
84
f"rule did not match action, rule_name={ rule_name } , rule_value={ rule_match_value } , "
85
85
f"name={ feature_name } , context_value={ str (context_value )} "
86
86
)
87
87
return False # context doesn't match condition
88
88
89
- self .loggerdebug (f"rule matched, rule_name={ rule_name } , rule_value={ rule_match_value } , name={ feature_name } " )
89
+ self .logger . debug (f"rule matched, rule_name={ rule_name } , rule_value={ rule_match_value } , name={ feature_name } " )
90
90
return True
91
91
92
92
def _evaluate_rules (
@@ -97,12 +97,12 @@ def _evaluate_rules(
97
97
rule_match_value = rule .get (schema .RULE_MATCH_VALUE )
98
98
99
99
# Context might contain PII data; do not log its value
100
- self .loggerdebug (f"Evaluating rule matching, rule={ rule_name } , feature={ feature_name } , default={ feat_default } " )
100
+ self .logger . debug (f"Evaluating rule matching, rule={ rule_name } , feature={ feature_name } , default={ feat_default } " )
101
101
if self ._evaluate_conditions (rule_name = rule_name , feature_name = feature_name , rule = rule , context = context ):
102
102
return bool (rule_match_value )
103
103
104
104
# no rule matched, return default value of feature
105
- self .loggerdebug (f"no rule matched, returning feature default, default={ feat_default } , name={ feature_name } " )
105
+ self .logger . debug (f"no rule matched, returning feature default, default={ feat_default } , name={ feature_name } " )
106
106
return feat_default
107
107
return False
108
108
@@ -149,7 +149,7 @@ def get_configuration(self) -> Union[Dict[str, Dict], Dict]:
149
149
```
150
150
"""
151
151
# parse result conf as JSON, keep in cache for max age defined in store
152
- self .loggerdebug (f"Fetching schema from registered store, store={ self ._store } " )
152
+ self .logger . debug (f"Fetching schema from registered store, store={ self ._store } " )
153
153
config = self ._store .get_configuration ()
154
154
validator = schema .SchemaValidator (schema = config )
155
155
validator .validate ()
@@ -193,21 +193,21 @@ def evaluate(self, *, name: str, context: Optional[Dict[str, Any]] = None, defau
193
193
try :
194
194
features = self .get_configuration ()
195
195
except ConfigurationStoreError as err :
196
- self .loggerdebug (f"Failed to fetch feature flags from store, returning default provided, reason={ err } " )
196
+ self .logger . debug (f"Failed to fetch feature flags from store, returning default provided, reason={ err } " )
197
197
return default
198
198
199
199
feature = features .get (name )
200
200
if feature is None :
201
- self .loggerdebug (f"Feature not found; returning default provided, name={ name } , default={ default } " )
201
+ self .logger . debug (f"Feature not found; returning default provided, name={ name } , default={ default } " )
202
202
return default
203
203
204
204
rules = feature .get (schema .RULES_KEY )
205
205
feat_default = feature .get (schema .FEATURE_DEFAULT_VAL_KEY )
206
206
if not rules :
207
- self .loggerdebug (f"no rules found, returning feature default, name={ name } , default={ feat_default } " )
207
+ self .logger . debug (f"no rules found, returning feature default, name={ name } , default={ feat_default } " )
208
208
return bool (feat_default )
209
209
210
- self .loggerdebug (f"looking for rule match, name={ name } , default={ feat_default } " )
210
+ self .logger . debug (f"looking for rule match, name={ name } , default={ feat_default } " )
211
211
return self ._evaluate_rules (feature_name = name , context = context , feat_default = bool (feat_default ), rules = rules )
212
212
213
213
def get_enabled_features (self , * , context : Optional [Dict [str , Any ]] = None ) -> List [str ]:
@@ -244,20 +244,20 @@ def get_enabled_features(self, *, context: Optional[Dict[str, Any]] = None) -> L
244
244
try :
245
245
features : Dict [str , Any ] = self .get_configuration ()
246
246
except ConfigurationStoreError as err :
247
- self .loggerdebug (f"Failed to fetch feature flags from store, returning empty list, reason={ err } " )
247
+ self .logger . debug (f"Failed to fetch feature flags from store, returning empty list, reason={ err } " )
248
248
return features_enabled
249
249
250
- self .loggerdebug ("Evaluating all features" )
250
+ self .logger . debug ("Evaluating all features" )
251
251
for name , feature in features .items ():
252
252
rules = feature .get (schema .RULES_KEY , {})
253
253
feature_default_value = feature .get (schema .FEATURE_DEFAULT_VAL_KEY )
254
254
if feature_default_value and not rules :
255
- self .loggerdebug (f"feature is enabled by default and has no defined rules, name={ name } " )
255
+ self .logger . debug (f"feature is enabled by default and has no defined rules, name={ name } " )
256
256
features_enabled .append (name )
257
257
elif self ._evaluate_rules (
258
258
feature_name = name , context = context , feat_default = feature_default_value , rules = rules
259
259
):
260
- self .loggerdebug (f"feature's calculated value is True, name={ name } " )
260
+ self .logger . debug (f"feature's calculated value is True, name={ name } " )
261
261
features_enabled .append (name )
262
262
263
263
return features_enabled
0 commit comments