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/core/logger.md
+24-1
Original file line number
Diff line number
Diff line change
@@ -274,13 +274,15 @@ You can remove any additional key from Logger state using `remove_keys`.
274
274
275
275
#### Clearing all state
276
276
277
+
##### Decorator with clear_state
278
+
277
279
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){target="_blank"}, this means that custom keys can be persisted across invocations. If you want all custom keys to be deleted, you can use `clear_state=True` param in `inject_lambda_context` decorator.
278
280
279
281
???+ tip "Tip: When is this useful?"
280
282
It is useful when you add multiple custom keys conditionally, instead of setting a default `None` value if not present. Any key with `None` value is automatically removed by Logger.
281
283
282
284
???+ danger "Danger: This can have unintended side effects if you use Layers"
283
-
Lambda Layers code is imported before the Lambda handler.
285
+
Lambda Layers code is imported before the Lambda handler. When a Lambda function starts, it first imports and executes all code in the Layers (including any global scope code) before proceeding to the function's own code.
284
286
285
287
This means that `clear_state=True` will instruct Logger to remove any keys previously added before Lambda handler execution proceeds.
286
288
@@ -304,6 +306,27 @@ Logger is commonly initialized in the global scope. Due to [Lambda Execution Con
You can call `clear_state()` as a method explicitly within your code to clear appended keys at any point during the execution of your Lambda invocation.
You can view all currently configured keys from the Logger state using the `get_current_keys()` method. This method is useful when you need to avoid overwriting keys that are already configured.
0 commit comments