Skip to content

Commit eeaec59

Browse files
jeromevdlJason Harris
authored and
Jason Harris
committed
update doc for ALC (#1520)
1 parent 223d196 commit eeaec59

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

Diff for: docs/core/logging.md

+20-14
Original file line numberDiff line numberDiff line change
@@ -596,12 +596,18 @@ via `samplingRate` attribute on annotation.
596596
POWERTOOLS_LOGGER_SAMPLE_RATE: 0.5
597597
```
598598

599-
## AWS Lambda Advanced Logging Controls
600-
With AWS [Lambda Advanced Logging Controls (ALC)](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-cloudwatchlogs.html#monitoring-cloudwatchlogs-advanced), you can control the output format of your logs as either `TEXT` or `JSON` and specify the minimum accepted log level for your application.
601-
Regardless of the output format setting in Lambda, Powertools for AWS Lambda will always output JSON formatted logging messages.
599+
## AWS Lambda Advanced Logging Controls (ALC)
602600

603-
When you have this feature enabled, log messages that don’t meet the configured log level are discarded by Lambda.
604-
For example, if you set the minimum log level to `WARN`, you will only receive `WARN` and `ERROR` messages in your AWS CloudWatch Logs, all other log levels will be discarded by Lambda.
601+
!!!question "When is it useful?"
602+
When you want to set a logging policy to drop informational or verbose logs for one or all AWS Lambda functions, regardless of runtime and logger used.
603+
604+
<!-- markdownlint-disable MD013 -->
605+
With [AWS Lambda Advanced Logging Controls (ALC)](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-cloudwatchlogs.html#monitoring-cloudwatchlogs-advanced){target="_blank"}, you can enforce a minimum log level that Lambda will accept from your application code.
606+
607+
When enabled, you should keep `Logger` and ALC log level in sync to avoid data loss.
608+
609+
Here's a sequence diagram to demonstrate how ALC will drop both `INFO` and `DEBUG` logs emitted from `Logger`, when ALC log level is stricter than `Logger`.
610+
<!-- markdownlint-enable MD013 -->
605611

606612
```mermaid
607613
sequenceDiagram
@@ -610,29 +616,29 @@ sequenceDiagram
610616
participant Application Logger
611617
612618
Note over Lambda service: AWS_LAMBDA_LOG_LEVEL="WARN"
619+
Note over Application Logger: POWERTOOLS_LOG_LEVEL="DEBUG"
620+
613621
Lambda service->>Lambda function: Invoke (event)
614622
Lambda function->>Lambda function: Calls handler
615-
Lambda function->>Application Logger: logger.warn("Something happened")
623+
Lambda function->>Application Logger: logger.error("Something happened")
616624
Lambda function-->>Application Logger: logger.debug("Something happened")
617625
Lambda function-->>Application Logger: logger.info("Something happened")
618-
619-
Lambda service->>Lambda service: DROP INFO and DEBUG logs
620-
626+
Lambda service--xLambda service: DROP INFO and DEBUG logs
621627
Lambda service->>CloudWatch Logs: Ingest error logs
622628
```
623629

624-
Logger will automatically listen for the `AWS_LAMBDA_LOG_FORMAT` and `AWS_LAMBDA_LOG_LEVEL` environment variables, and change behaviour if they’re found to ensure as much compatibility as possible.
625-
626630
### Priority of log level settings in Powertools for AWS Lambda
627631

628-
When the Advanced Logging Controls feature is enabled, we are unable to increase the minimum log level below the `AWS_LAMBDA_LOG_LEVEL` environment variable value, see [AWS Lambda service documentation](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-cloudwatchlogs.html#monitoring-cloudwatchlogs-log-level) for more details.
629-
630632
We prioritise log level settings in this order:
631633

632634
1. `AWS_LAMBDA_LOG_LEVEL` environment variable
633635
2. `POWERTOOLS_LOG_LEVEL` environment variable
634636

635-
In the event you have set `POWERTOOLS_LOG_LEVEL` to a level lower than the ACL setting, Powertools for AWS Lambda will output a warning log message informing you that your messages will be discarded by Lambda.
637+
If you set `Logger` level lower than ALC, we will emit a warning informing you that your messages will be discarded by Lambda.
638+
639+
> **NOTE**
640+
>
641+
> With ALC enabled, we are unable to increase the minimum log level below the `AWS_LAMBDA_LOG_LEVEL` environment variable value, see [AWS Lambda service documentation](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-cloudwatchlogs.html#monitoring-cloudwatchlogs-log-level){target="_blank"} for more details.
636642
637643
### Timestamp format
638644

0 commit comments

Comments
 (0)