Skip to content

Commit 3cdc27a

Browse files
committed
docs(logger): adjust wording and unnecessary collapse
1 parent 2ff5edf commit 3cdc27a

File tree

1 file changed

+23
-30
lines changed

1 file changed

+23
-30
lines changed

docs/core/logger.md

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ Key | Example
129129

130130
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.
131131

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"
134133

135134
=== "log_handler_event.py"
136135

@@ -148,8 +147,7 @@ When debugging in non-production environments, you can instruct Logger to log th
148147

149148
You can set a Correlation ID using `correlation_id_path` param by passing a [JMESPath expression](https://jmespath.org/tutorial.html){target="_blank"}.
150149

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"
153151

154152
=== "collect.py"
155153

@@ -438,8 +436,8 @@ You can remove any additional key from Logger state using `remove_keys`.
438436

439437
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.
440438

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.
443441

444442
???+ danger "Danger: This can have unintended side effects if you use Layers"
445443
Lambda Layers code is imported before the Lambda handler.
@@ -536,6 +534,21 @@ Use `logger.exception` method to log contextual information about exceptions. Lo
536534

537535
## Advanced
538536

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"`**.
543+
544+
Name | Expression | Description
545+
------------------------------------------------- | ------------------------------------------------- | ---------------------------------------------------------------------------------
546+
**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+
539552
### Reusing Logger across your code
540553

541554
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
582595

583596
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.
584597

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"
587599

588600
=== "collect.py"
589601

@@ -871,8 +883,7 @@ For **minor changes like remapping keys** after all log record processing has co
871883

872884
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.
873885

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."
876887

877888
=== "collect.py"
878889

@@ -949,21 +960,6 @@ As parameters don't always translate well between them, you can pass any callabl
949960
# custom_serializer=functools.partial(orjson.dumps, option=orjson.OPT_SERIALIZE_NUMPY)
950961
```
951962

952-
## Built-in Correlation ID expressions
953-
954-
You can use any of the following built-in JMESPath expressions as part of [inject_lambda_context decorator](#setting-a-correlation-id).
955-
956-
???+ note "Note: Escaping necessary for the `-` character"
957-
Any object key named with `-` must be escaped, for example **`request.headers."x-amzn-trace-id"`**.
958-
959-
Name | Expression | Description
960-
------------------------------------------------- | ------------------------------------------------- | ---------------------------------------------------------------------------------
961-
**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-
967963
## Testing your code
968964

969965
### Inject Lambda Context
@@ -1020,8 +1016,7 @@ This is a Pytest sample that provides the minimum information necessary for Logg
10201016
your_lambda_handler(test_event, lambda_context)
10211017
```
10221018

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"
10251020

10261021
### Pytest live log feature
10271022

@@ -1114,6 +1109,4 @@ Here's an example where we persist `payment_id` not `request_id`. Note that `pay
11141109

11151110
**How do I aggregate and search Powertools logs across accounts?**
11161111

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

Comments
 (0)