From 8f61fe1f0cd8e365931b9e9e3da4de7e78a87271 Mon Sep 17 00:00:00 2001 From: Alexander Schueren Date: Tue, 19 Dec 2023 10:53:03 +0100 Subject: [PATCH 1/4] docs: removed required settings and added section for envs --- docs/core/logger.md | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/docs/core/logger.md b/docs/core/logger.md index bd0be2de36..740c250f33 100644 --- a/docs/core/logger.md +++ b/docs/core/logger.md @@ -50,8 +50,6 @@ These settings will be used across all logs emitted: | ---------------------- | ---------------------------------------------------------------------------------------------------------------- | ------------------------------- | ------------------- | ------------------------------------------------------ | ------------------- | --------------------- | | **Service name** | Sets the name of service of which the Lambda function is part of, that will be present across all log statements | `POWERTOOLS_SERVICE_NAME` | `service_undefined` | Any string | `serverlessAirline` | `serviceName` | | **Logging level** | Sets how verbose Logger should be, from the most verbose to the least verbose (no logs) | `POWERTOOLS_LOG_LEVEL` | `INFO` | `DEBUG`, `INFO`, `WARN`, `ERROR`, `CRITICAL`, `SILENT` | `ERROR` | `logLevel` | -| **Log incoming event** | Whether to log or not the incoming event when using the decorator or middleware | `POWERTOOLS_LOGGER_LOG_EVENT` | `false` | `true`, `false` | `false` | `logEvent` | -| **Debug log sampling** | Probability that a Lambda invocation will print all the log items regardless of the log level setting | `POWERTOOLS_LOGGER_SAMPLE_RATE` | `0` | `0.0` to `1` | `0.5` | `sampleRateValue` | #### Example using AWS Serverless Application Model (SAM) @@ -153,7 +151,7 @@ In each case, the printed log will look like this: } ``` -#### Log incoming event +### Log incoming event When debugging in non-production environments, you can instruct Logger to log the incoming event with the middleware/decorator parameter `logEvent` or via `POWERTOOLS_LOGGER_LOG_EVENT` env var set to `true`. @@ -174,6 +172,9 @@ When debugging in non-production environments, you can instruct Logger to log th 1. Binding your handler method allows your handler to access `this` within the class methods. +Logging incoming events only works with middy or decorator by using `injectLambdaContext`. +Only setting `POWEETOOLS_LOGGER_LOG_EVENT` to `true` will not log the incoming event. + ### Appending persistent additional log keys and values You can append additional persistent keys and values in the logs generated during a Lambda invocation using either mechanism: @@ -389,6 +390,18 @@ The error will be logged with default key name `error`, but you can also pass yo !!! tip "Logging errors and log level" You can also log errors using the `warn`, `info`, and `debug` methods. Be aware of the log level though, you might miss those errors when analyzing the log later depending on the log level configuration. +### Environment variables + +The following environment variables are available to configure Logger at a global scope: + + +| Setting | Description | Environment variable | Default Value | Allowed Values | Example Value | Constructor parameter | +| ---------------------- |-----------------------------------------------------------------------------------------------------------------| ------------------------------- | ------------------- | ------------------------------------------------------ | ------------------- | --------------------- | +| **Service name** | Sets the name of service of which the Lambda function is part of, that will be present across all log statements | `POWERTOOLS_SERVICE_NAME` | `service_undefined` | Any string | `serverlessAirline` | `serviceName` | +| **Logging level** | Sets how verbose Logger should be, from the most verbose to the least verbose (no logs) | `POWERTOOLS_LOG_LEVEL` | `INFO` | `DEBUG`, `INFO`, `WARN`, `ERROR`, `CRITICAL`, `SILENT` | `ERROR` | `logLevel` | +| **Log event** | Whether to log or not the incoming event when using the decorator or middleware | `POWERTOOLS_LOGGER_LOG_EVENT` | `false` | `true`, `false` | `true` | `logEvent` | +| **Sample rate** | Probability that a Lambda invocation will print all the log items regardless of the log level setting | `POWERTOOLS_LOGGER_SAMPLE_RATE` | `0` | `0.0` to `1.0` | `0.1` | `sampleRateValue` | + ## Advanced From 386770527fa7ac87d3c57348dc70c65a7c94c6b6 Mon Sep 17 00:00:00 2001 From: Alexander Schueren Date: Tue, 19 Dec 2023 11:31:08 +0100 Subject: [PATCH 2/4] fix typo --- docs/core/logger.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/logger.md b/docs/core/logger.md index 740c250f33..68b084d8bb 100644 --- a/docs/core/logger.md +++ b/docs/core/logger.md @@ -173,7 +173,7 @@ When debugging in non-production environments, you can instruct Logger to log th 1. Binding your handler method allows your handler to access `this` within the class methods. Logging incoming events only works with middy or decorator by using `injectLambdaContext`. -Only setting `POWEETOOLS_LOGGER_LOG_EVENT` to `true` will not log the incoming event. +Only setting `POWERTOOLS_LOGGER_LOG_EVENT` to `true` will not log the incoming event. ### Appending persistent additional log keys and values From 60d3c5d0e9b12e181268c024c9b11109a7d12740 Mon Sep 17 00:00:00 2001 From: Alexander Schueren Date: Tue, 19 Dec 2023 13:38:41 +0100 Subject: [PATCH 3/4] remove env section in logs, adjust woring and link to api and index page --- docs/core/logger.md | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/docs/core/logger.md b/docs/core/logger.md index 68b084d8bb..8d4cbc78d8 100644 --- a/docs/core/logger.md +++ b/docs/core/logger.md @@ -41,8 +41,7 @@ The `Logger` utility must always be instantiated outside the Lambda handler. By ``` ### Utility settings - -The library requires two settings. You can set them as environment variables, or pass them in the constructor. +The library has three optional settings, which can be set via environment variables or passed in the constructor. These settings will be used across all logs emitted: @@ -50,6 +49,10 @@ These settings will be used across all logs emitted: | ---------------------- | ---------------------------------------------------------------------------------------------------------------- | ------------------------------- | ------------------- | ------------------------------------------------------ | ------------------- | --------------------- | | **Service name** | Sets the name of service of which the Lambda function is part of, that will be present across all log statements | `POWERTOOLS_SERVICE_NAME` | `service_undefined` | Any string | `serverlessAirline` | `serviceName` | | **Logging level** | Sets how verbose Logger should be, from the most verbose to the least verbose (no logs) | `POWERTOOLS_LOG_LEVEL` | `INFO` | `DEBUG`, `INFO`, `WARN`, `ERROR`, `CRITICAL`, `SILENT` | `ERROR` | `logLevel` | +| **Sample rate** | Probability that a Lambda invocation will print all the log items regardless of the log level setting | `POWERTOOLS_LOGGER_SAMPLE_RATE` | `0` | `0.0` to `1.0` | `0.1` | `sampleRateValue` | + +See all enivronment variables in the [Environment variables](../index.md/#environment-variables) section. +Check API docs to learn more about [Logger constructor options](https://docs.powertools.aws.dev/lambda/typescript/latest/api/types/_aws_lambda_powertools_logger.types.ConstructorOptions.html){target="_blank"}. #### Example using AWS Serverless Application Model (SAM) @@ -390,19 +393,6 @@ The error will be logged with default key name `error`, but you can also pass yo !!! tip "Logging errors and log level" You can also log errors using the `warn`, `info`, and `debug` methods. Be aware of the log level though, you might miss those errors when analyzing the log later depending on the log level configuration. -### Environment variables - -The following environment variables are available to configure Logger at a global scope: - - -| Setting | Description | Environment variable | Default Value | Allowed Values | Example Value | Constructor parameter | -| ---------------------- |-----------------------------------------------------------------------------------------------------------------| ------------------------------- | ------------------- | ------------------------------------------------------ | ------------------- | --------------------- | -| **Service name** | Sets the name of service of which the Lambda function is part of, that will be present across all log statements | `POWERTOOLS_SERVICE_NAME` | `service_undefined` | Any string | `serverlessAirline` | `serviceName` | -| **Logging level** | Sets how verbose Logger should be, from the most verbose to the least verbose (no logs) | `POWERTOOLS_LOG_LEVEL` | `INFO` | `DEBUG`, `INFO`, `WARN`, `ERROR`, `CRITICAL`, `SILENT` | `ERROR` | `logLevel` | -| **Log event** | Whether to log or not the incoming event when using the decorator or middleware | `POWERTOOLS_LOGGER_LOG_EVENT` | `false` | `true`, `false` | `true` | `logEvent` | -| **Sample rate** | Probability that a Lambda invocation will print all the log items regardless of the log level setting | `POWERTOOLS_LOGGER_SAMPLE_RATE` | `0` | `0.0` to `1.0` | `0.1` | `sampleRateValue` | - - ## Advanced ### Log levels From efb5b712e46e5828ce2e2b16a18cfd6b4f5851b4 Mon Sep 17 00:00:00 2001 From: Alexander Schueren Date: Tue, 19 Dec 2023 13:45:14 +0100 Subject: [PATCH 4/4] clarified wording on logEvent --- docs/core/logger.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/core/logger.md b/docs/core/logger.md index 8d4cbc78d8..2fb54ccee7 100644 --- a/docs/core/logger.md +++ b/docs/core/logger.md @@ -156,7 +156,7 @@ In each case, the printed log will look like this: ### Log incoming event -When debugging in non-production environments, you can instruct Logger to log the incoming event with the middleware/decorator parameter `logEvent` or via `POWERTOOLS_LOGGER_LOG_EVENT` env var set to `true`. +When debugging in non-production environments, you can instruct Logger to log the incoming event with the middleware/decorator parameter `logEvent`. ???+ warning This is disabled by default to prevent sensitive info being logged @@ -175,8 +175,7 @@ When debugging in non-production environments, you can instruct Logger to log th 1. Binding your handler method allows your handler to access `this` within the class methods. -Logging incoming events only works with middy or decorator by using `injectLambdaContext`. -Only setting `POWERTOOLS_LOGGER_LOG_EVENT` to `true` will not log the incoming event. +Use `POWERTOOLS_LOGGER_LOG_EVENT` environment variable to enable or disable (`true`/`false`) this feature. ### Appending persistent additional log keys and values