Skip to content

Commit

Permalink
Added evaluation logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrykPiwowarczyk committed Oct 5, 2023
1 parent 08bfb74 commit 57645a2
Showing 1 changed file with 41 additions and 26 deletions.
67 changes: 41 additions & 26 deletions Sources/FeaturevisorSDK/Instance+Evaluation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extension FeaturevisorInstance {
reason: .disabled
)

logger.debug("feature is disabled", ["featureKey": featureKey]) // TODO: Log evaluation object. Make it encodable
logger.debug("feature is disabled", evaluation.toDictionary())

return evaluation
}
Expand All @@ -35,7 +35,7 @@ extension FeaturevisorInstance {
variationValue: variationValue
)

logger.debug("using sticky variation", ["featureKey": featureKey]) // TODO: Log evaluation object. Make it encodable
logger.debug("using sticky variation", evaluation.toDictionary())

return evaluation
}
Expand All @@ -48,7 +48,7 @@ extension FeaturevisorInstance {
variationValue: variationValue
)

logger.debug("using initial variation", ["featureKey": featureKey]) // TODO: Log evaluation object. Make it encodable
logger.debug("using initial variation", evaluation.toDictionary())

return evaluation
}
Expand All @@ -60,7 +60,7 @@ extension FeaturevisorInstance {
reason: .notFound
)

logger.warn("feature not found", ["featureKey": featureKey]) // TODO: Log evaluation object. Make it encodable
logger.warn("feature not found", evaluation.toDictionary())

return evaluation
}
Expand All @@ -72,8 +72,7 @@ extension FeaturevisorInstance {
reason: .noVariations
)

logger.warn("no variations", ["featureKey": featureKey]) // TODO: Log evaluation object. Make it encodable

logger.warn("no variations", evaluation.toDictionary())
return evaluation
}

Expand All @@ -96,7 +95,7 @@ extension FeaturevisorInstance {
variation: variation
)

logger.debug("forced variation found", ["featureKey": featureKey]) // TODO: Log evaluation object. Make it encodable
logger.debug("forced variation found", evaluation.toDictionary())

return evaluation
}
Expand Down Expand Up @@ -131,7 +130,7 @@ extension FeaturevisorInstance {
variation: variation
)

logger.debug("override from rule", ["featureKey": featureKey]) // TODO: Log evaluation object. Make it encodable
logger.debug("override from rule", evaluation.toDictionary())

return evaluation
}
Expand All @@ -152,7 +151,7 @@ extension FeaturevisorInstance {
variation: variation
)

logger.debug("allocated variation", ["featureKey": featureKey]) // TODO: Log evaluation object. Make it encodable
logger.debug("allocated variation", evaluation.toDictionary())

return evaluation
}
Expand All @@ -166,7 +165,7 @@ extension FeaturevisorInstance {
bucketValue: bucketValue
)

logger.debug("no matched variation", ["featureKey": featureKey]) // TODO: Log evaluation object. Make it encodable
logger.debug("no matched variation", evaluation.toDictionary())

return evaluation
}
Expand All @@ -185,7 +184,7 @@ extension FeaturevisorInstance {
sticky: stickyFeature
)

logger.debug("using sticky enabled", ["featureKey": featureKey]) // TODO: Log evaluation object. Make it encodable
logger.debug("using sticky enabled", evaluation.toDictionary())

return evaluation
}
Expand All @@ -199,7 +198,7 @@ extension FeaturevisorInstance {
initial: initialFeature
)

logger.debug("using initial enabled", ["featureKey": featureKey]) // TODO: Log evaluation object. Make it encodable
logger.debug("using initial enabled", evaluation.toDictionary())

return evaluation
}
Expand All @@ -213,7 +212,7 @@ extension FeaturevisorInstance {
reason: .notFound
)

logger.warn("feature not found", ["featureKey": featureKey]) // TODO: Log evaluation object. Make it encodable
logger.warn("feature not found", evaluation.toDictionary())

return evaluation
}
Expand All @@ -235,7 +234,7 @@ extension FeaturevisorInstance {
enabled: force.enabled
)

logger.debug("forced enabled found", ["featureKey": featureKey]) // TODO: Log evaluation object. Make it encodable
logger.debug("forced enabled found", evaluation.toDictionary())

return evaluation
}
Expand Down Expand Up @@ -321,7 +320,7 @@ extension FeaturevisorInstance {
enabled: false
)

logger.debug("not matched", ["featureKey": featureKey]) // TODO: Log evaluation object. Make it encodable
logger.debug("not matched", evaluation.toDictionary())

return evaluation
}
Expand All @@ -337,7 +336,7 @@ extension FeaturevisorInstance {
traffic: matchedTraffic
)

logger.debug("override from rule", ["featureKey": featureKey]) // TODO: Log evaluation object. Make it encodable
logger.debug("override from rule", evaluation.toDictionary())

return evaluation
}
Expand Down Expand Up @@ -384,7 +383,7 @@ extension FeaturevisorInstance {
if flag.enabled == false {
evaluation = Evaluation(featureKey: featureKey, reason: .disabled)

logger.debug("feature is disabled", ["featureKey": featureKey]) // TODO: Log evaluation object. Make it encodable
logger.debug("feature is disabled", evaluation.toDictionary())

return evaluation
}
Expand All @@ -398,7 +397,7 @@ extension FeaturevisorInstance {
variableValue: variableValue
)

logger.debug("using sticky variable", ["featureKey": featureKey]) // TODO: Log evaluation object. Make it encodable
logger.debug("using sticky variable", evaluation.toDictionary())

return evaluation
}
Expand All @@ -414,7 +413,7 @@ extension FeaturevisorInstance {
variableValue: variableValue
)

logger.debug("using initial variable", ["featureKey": featureKey]) // TODO: Log evaluation object. Make it encodable
logger.debug("using initial variable", evaluation.toDictionary())

return evaluation
}
Expand All @@ -428,7 +427,7 @@ extension FeaturevisorInstance {
variableKey: variableKey
)

logger.warn("feature not found in datafile", ["featureKey": featureKey]) // TODO: Log evaluation object. Make it encodable
logger.warn("feature not found in datafile", evaluation.toDictionary())

return evaluation
}
Expand All @@ -445,7 +444,7 @@ extension FeaturevisorInstance {
variableKey: variableKey
)

logger.warn("variable schema not found", ["featureKey": featureKey]) // TODO: Log evaluation object. Make it encodable
logger.warn("variable schema not found", evaluation.toDictionary())

return evaluation
}
Expand All @@ -464,7 +463,7 @@ extension FeaturevisorInstance {
variableSchema: variableSchema
)

logger.debug("forced variable", ["featureKey": featureKey]) // TODO: Log evaluation object. Make it encodable
logger.debug("forced variable", evaluation.toDictionary())

return evaluation
}
Expand Down Expand Up @@ -493,7 +492,7 @@ extension FeaturevisorInstance {
variableSchema: variableSchema
)

logger.debug("override from rule", ["featureKey": featureKey]) // TODO: Log evaluation object. Make it encodable
logger.debug("override from rule", evaluation.toDictionary())

return evaluation
}
Expand Down Expand Up @@ -541,7 +540,7 @@ extension FeaturevisorInstance {
variableSchema: variableSchema
)

logger.debug("variable override", ["featureKey": featureKey]) // TODO: Log evaluation object. Make it encodable
logger.debug("variable override", evaluation.toDictionary())

return evaluation
}
Expand All @@ -558,7 +557,7 @@ extension FeaturevisorInstance {
variableSchema: variableSchema
)

logger.debug("allocated variable", ["featureKey": featureKey]) // TODO: Log evaluation object. Make it encodable
logger.debug("allocated variable", evaluation.toDictionary())

return evaluation
}
Expand All @@ -576,7 +575,7 @@ extension FeaturevisorInstance {
variableSchema: variableSchema
)

logger.debug("using default value", ["featureKey": featureKey]) // TODO: Log evaluation object. Make it encodable
logger.debug("using default value", evaluation.toDictionary())

return evaluation
}
Expand Down Expand Up @@ -652,3 +651,19 @@ extension FeaturevisorInstance {
return value
}
}

extension FeaturevisorInstance {

func toDictionary(_ evaluation: Evaluation) -> [String: Any] {

var dictionary = [String: Any]()
let mirror = Mirror(reflecting: self)

for child in mirror.children {
if let key = child.label {
dictionary[key] = child.value
}
}
return dictionary
}
}

0 comments on commit 57645a2

Please sign in to comment.