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
+23-30Lines changed: 23 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -129,8 +129,7 @@ Key | Example
129
129
130
130
When debugging in non-production environments, you can instruct Logger to log the incoming event with `log_event` param or via `POWERTOOLS_LOGGER_LOG_EVENT` env var.
131
131
132
-
???+ warning
133
-
This is disabled by default to prevent sensitive info being logged.
132
+
!!! warning "Warning: This is disabled by default to prevent sensitive info being logged"
134
133
135
134
=== "log_handler_event.py"
136
135
@@ -148,8 +147,7 @@ When debugging in non-production environments, you can instruct Logger to log th
148
147
149
148
You can set a Correlation ID using `correlation_id_path` param by passing a [JMESPath expression](https://jmespath.org/tutorial.html){target="_blank"}.
150
149
151
-
???+ tip
152
-
You can retrieve correlation IDs via `get_correlation_id` method
150
+
!!! tip "Tip: You can retrieve correlation IDs via `get_correlation_id` method"
153
151
154
152
=== "collect.py"
155
153
@@ -438,8 +436,8 @@ You can remove any additional key from Logger state using `remove_keys`.
438
436
439
437
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), 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.
440
438
441
-
???+ info
442
-
This 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.
439
+
???+ tip "Tip: When is this useful?"
440
+
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.
443
441
444
442
???+ danger "Danger: This can have unintended side effects if you use Layers"
445
443
Lambda Layers code is imported before the Lambda handler.
@@ -536,6 +534,21 @@ Use `logger.exception` method to log contextual information about exceptions. Lo
536
534
537
535
## Advanced
538
536
537
+
### Built-in Correlation ID expressions
538
+
539
+
You can use any of the following built-in JMESPath expressions as part of [inject_lambda_context decorator](#setting-a-correlation-id).
540
+
541
+
???+ note "Note: Any object key named with `-` must be escaped"
542
+
For example, **`request.headers."x-amzn-trace-id"`**.
**API_GATEWAY_REST** | `"requestContext.requestId"` | API Gateway REST API request ID
547
+
**API_GATEWAY_HTTP** | `"requestContext.requestId"` | API Gateway HTTP API request ID
548
+
**APPSYNC_RESOLVER** | `'request.headers."x-amzn-trace-id"'` | AppSync X-Ray Trace ID
549
+
**APPLICATION_LOAD_BALANCER** | `'headers."x-amzn-trace-id"'` | ALB X-Ray Trace ID
550
+
**EVENT_BRIDGE** | `"id"` | EventBridge Event ID
551
+
539
552
### Reusing Logger across your code
540
553
541
554
Logger supports inheritance via `child` parameter. This allows you to create multiple Loggers across your code base, and propagate changes such as new keys to all Loggers.
@@ -582,8 +595,7 @@ You can use values ranging from `0.0` to `1` (100%) when setting `POWERTOOLS_LOG
582
595
583
596
Sampling decision happens at the Logger initialization. This means sampling may happen significantly more or less than depending on your traffic patterns, for example a steady low number of invocations and thus few cold starts.
584
597
585
-
???+ note
586
-
If you want Logger to calculate sampling upon every invocation, please open a [feature request](https://github.com/awslabs/aws-lambda-powertools-python/issues/new?assignees=&labels=feature-request%2C+triage&template=feature_request.md&title=).
598
+
!!! note "Note: Open a [feature request](https://github.com/awslabs/aws-lambda-powertools-python/issues/new?assignees=&labels=feature-request%2C+triage&template=feature_request.md&title=) if you want Logger to calculate sampling for every invocation"
587
599
588
600
=== "collect.py"
589
601
@@ -871,8 +883,7 @@ For **minor changes like remapping keys** after all log record processing has co
871
883
872
884
For **replacing the formatter entirely**, you can subclass `BasePowertoolsFormatter`, implement `append_keys` method, and override `format` standard logging method. This ensures the current feature set of Logger like [injecting Lambda context](#capturing-lambda-context-info) and [sampling](#sampling-debug-logs) will continue to work.
873
885
874
-
???+ info
875
-
You might need to implement `remove_keys` method if you make use of the feature too.
886
+
!!! info "Info: You might need to implement `remove_keys` method if you make use of the feature too."
876
887
877
888
=== "collect.py"
878
889
@@ -949,21 +960,6 @@ As parameters don't always translate well between them, you can pass any callabl
**API_GATEWAY_REST** | `"requestContext.requestId"` | API Gateway REST API request ID
962
-
**API_GATEWAY_HTTP** | `"requestContext.requestId"` | API Gateway HTTP API request ID
963
-
**APPSYNC_RESOLVER** | `'request.headers."x-amzn-trace-id"'` | AppSync X-Ray Trace ID
964
-
**APPLICATION_LOAD_BALANCER** | `'headers."x-amzn-trace-id"'` | ALB X-Ray Trace ID
965
-
**EVENT_BRIDGE** | `"id"` | EventBridge Event ID
966
-
967
963
## Testing your code
968
964
969
965
### Inject Lambda Context
@@ -1020,8 +1016,7 @@ This is a Pytest sample that provides the minimum information necessary for Logg
1020
1016
your_lambda_handler(test_event, lambda_context)
1021
1017
```
1022
1018
1023
-
???+ tip
1024
-
If you're using pytest and are looking to assert plain log messages, do check out the built-in [caplog fixture](https://docs.pytest.org/en/latest/how-to/logging.html){target="_blank"}.
1019
+
!!! tip "Tip: Check out the built-in [Pytest caplog fixture](https://docs.pytest.org/en/latest/how-to/logging.html){target="_blank"} to assert plain log messages"
1025
1020
1026
1021
### Pytest live log feature
1027
1022
@@ -1114,6 +1109,4 @@ Here's an example where we persist `payment_id` not `request_id`. Note that `pay
1114
1109
1115
1110
**How do I aggregate and search Powertools logs across accounts?**
1116
1111
1117
-
As of now, ElasticSearch (ELK) or 3rd party solutions are best suited to this task.
1118
-
1119
-
Please see this discussion for more information: https://github.com/awslabs/aws-lambda-powertools-python/issues/460
1112
+
As of now, ElasticSearch (ELK) or 3rd party solutions are best suited to this task. Please refer to this [discussion for more details](https://github.com/awslabs/aws-lambda-powertools-python/issues/460)
0 commit comments