You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/hooks.md
+70Lines changed: 70 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -84,6 +84,76 @@ val loggingHook = FeatureHook.logging(
84
84
FeatureFlags.addHook(loggingHook)
85
85
```
86
86
87
+
### Structured Logging Hook
88
+
89
+
A richer logging hook that adds machine-readable annotations to log output via `ZIO.logAnnotate`. Unlike the basic `logging()` hook which produces plain text messages, structured logging attaches typed fields that are preserved by `zio-logging` backends (JSON, SLF4J MDC, OpenTelemetry, etc.).
90
+
91
+
```scala
92
+
valhook=FeatureHook.structuredLogging(
93
+
beforeLevel =Some(LogLevel.Debug), // None to disable
94
+
afterLevel =Some(LogLevel.Debug),
95
+
errorLevel =Some(LogLevel.Warning),
96
+
logContext =false, // include evaluation context in annotations
When `logContext = true`, the hook includes the evaluation context (targeting key + attributes) in log annotations. The `redactKeys` parameter specifies which attribute keys should have their values replaced with `"[REDACTED]"` — the key is still logged so you know the attribute was present, but the value is hidden.
123
+
124
+
```scala
125
+
valhook=FeatureHook.structuredLogging(
126
+
logContext =true,
127
+
redactKeys =Set("email", "ssn")
128
+
)
129
+
130
+
// With context: targetingKey="user-123", email="john@example.com", plan="premium"
131
+
// Produces annotations:
132
+
// flag.context.targetingKey = "user-123" ← not redacted
133
+
// flag.context.email = "[REDACTED]" ← value hidden
134
+
// flag.context.plan = "premium" ← not redacted
135
+
```
136
+
137
+
When `logContext = false` (default), no context attributes are logged and `redactKeys` has no effect.
138
+
139
+
Note: `redactKeys` only applies to context attributes, not to the targeting key. The targeting key is always logged as-is when `logContext` is enabled.
0 commit comments