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
* capture correlation ids
* chore: docs and javadocs update
* support any Json Pointer path
* docs: correlation id extraction
* feat: ability to clear state of logger on each request for custom keys
* docs: ability to clear state of logger on each request for custom keys
Co-authored-by: Pankaj Agrawal <[email protected]>
Copy file name to clipboardExpand all lines: docs/core/logging.md
+64
Original file line number
Diff line number
Diff line change
@@ -224,6 +224,9 @@ for known event sources, where either a request ID or X-Ray Trace ID are present
224
224
225
225
## Appending additional keys
226
226
227
+
!!! info "Custom keys are persisted across warm invocations"
228
+
Always set additional keys as part of your handler to ensure they have the latest value, or explicitly clear them with [`clearState=true`](#clearing-all-state).
229
+
227
230
You can append your own keys to your existing logs via `appendKey`.
228
231
229
232
=== "App.java"
@@ -286,6 +289,67 @@ You can remove any additional key from entry using `LoggingUtils.removeKeys()`.
286
289
}
287
290
```
288
291
292
+
### Clearing all state
293
+
294
+
Logger is commonly initialized in the global scope. Due to [Lambda Execution Context reuse](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-context.html),
295
+
this means that custom keys can be persisted across invocations. If you want all custom keys to be deleted, you can use
296
+
`clearState=true` attribute on `@Logging` annotation.
297
+
298
+
299
+
=== "App.java"
300
+
301
+
```java hl_lines="8 12"
302
+
/**
303
+
* Handler for requests to Lambda function.
304
+
*/
305
+
public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
306
+
307
+
Logger log = LogManager.getLogger();
308
+
309
+
@Logging(clearState = true)
310
+
public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEvent input, final Context context) {
Copy file name to clipboardExpand all lines: powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/LambdaLoggingAspect.java
Copy file name to clipboardExpand all lines: powertools-logging/src/test/java/software/amazon/lambda/powertools/logging/internal/LambdaLoggingAspectTest.java
0 commit comments