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
|**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`|
52
-
|**Logging level**| Sets how verbose Logger should be, from the most verbose to the least verbose (no logs) |`LOG_LEVEL`|`info`|`DEBUG`, `INFO`, `WARN`, `ERROR`, `SILENT`|`ERROR`|`logLevel`|
53
-
|**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`|
54
-
|**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`|
49
+
| 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`|
52
+
|**Logging level**| Sets how verbose Logger should be, from the most verbose to the least verbose (no logs) |`LOG_LEVEL`|`info`|`DEBUG`, `INFO`, `WARN`, `ERROR`, `SILENT`|`ERROR`|`logLevel`|
53
+
|**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`|
54
+
|**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`|
55
55
56
56
#### Example using AWS Serverless Application Model (SAM)
57
57
@@ -80,7 +80,7 @@ These settings will be used across all logs emitted:
80
80
Your Logger will include the following keys to your structured logging (default log formatter):
You can install Middy by running `npm i @middy/core`.
113
113
Learn more about [its usage and lifecycle in the official Middy documentation](https://middy.js.org/docs/intro/getting-started){target="_blank"}.
114
114
115
-
```typescript hl_lines="1-2 10-11"
115
+
```typescript hl_lines="1-2 13"
116
116
--8<-- "docs/snippets/logger/middy.ts"
117
117
```
118
118
@@ -126,7 +126,7 @@ Key | Example
126
126
127
127
=== "Manual"
128
128
129
-
```typescript hl_lines="7"
129
+
```typescript hl_lines="6"
130
130
--8<-- "docs/snippets/logger/manual.ts"
131
131
```
132
132
@@ -158,7 +158,7 @@ When debugging in non-production environments, you can instruct Logger to log th
158
158
159
159
=== "Middy Middleware"
160
160
161
-
```typescript hl_lines="11"
161
+
```typescript hl_lines="10"
162
162
--8<-- "docs/snippets/logger/eventMiddy.ts"
163
163
```
164
164
@@ -182,7 +182,7 @@ To remove the keys you added, you can use the `removeKeys` method.
182
182
183
183
=== "handler.ts"
184
184
185
-
```typescript hl_lines="5-13 17-25 30"
185
+
```typescript hl_lines="5-13 17-25 32"
186
186
--8<-- "docs/snippets/logger/appendKeys.ts"
187
187
```
188
188
=== "Example CloudWatch Logs excerpt"
@@ -229,7 +229,7 @@ If you want to make sure that persistent attributes added **inside the handler f
229
229
230
230
=== "Middy Middleware"
231
231
232
-
```typescript hl_lines="27"
232
+
```typescript hl_lines="30"
233
233
--8<-- "docs/snippets/logger/clearStateMiddy.ts"
234
234
```
235
235
@@ -294,7 +294,7 @@ You can append additional data to a single log item by passing objects as additi
294
294
295
295
=== "handler.ts"
296
296
297
-
```typescript hl_lines="14 18-20 24 32"
297
+
```typescript hl_lines="16-18 23-25 37"
298
298
--8<-- "docs/snippets/logger/extraData.ts"
299
299
```
300
300
=== "Example CloudWatch Logs excerpt"
@@ -347,7 +347,7 @@ The error will be logged with default key name `error`, but you can also pass yo
347
347
348
348
=== "handler.ts"
349
349
350
-
```typescript hl_lines="11 18"
350
+
```typescript hl_lines="13 20-22"
351
351
--8<-- "docs/snippets/logger/logError.ts"
352
352
```
353
353
@@ -396,7 +396,7 @@ The `createChild` method allows you to create a child instance of the Logger, wh
396
396
397
397
=== "handler.ts"
398
398
399
-
```typescript hl_lines="9-11 18-19"
399
+
```typescript hl_lines="16-18"
400
400
--8<-- "docs/snippets/logger/createChild.ts"
401
401
```
402
402
@@ -447,7 +447,8 @@ For example, by setting the "sample rate" to `0.5`, roughly 50% of your lambda i
447
447
448
448
However, it might still be useful to print all the logs (including debug ones) of a very small percentage of invocations to have a better understanding of the behaviour of your code in production even when there are no errors.
449
449
450
-
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.
450
+
**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.
451
+
If you want to reset the sampling decision and refresh it for each invocation, you can call the `logger.refreshSampleRateCalculation()` method at the beginning or end of your handler.
|**Service**| Optionally, sets **service** metric dimension across all metrics|`POWERTOOLS_SERVICE_NAME`|`service_undefined`| Any string |`serverlessAirline`|`serviceName`|
69
-
|**Metric namespace**| Logical container where all metrics will be placed |`POWERTOOLS_METRICS_NAMESPACE`|`default_namespace`| Any string |`serverlessAirline`|`default_namespace`|
|**Service**| Optionally, sets **service** metric dimension across all metrics|`POWERTOOLS_SERVICE_NAME`|`service_undefined`| Any string |`serverlessAirline`|`serviceName`|
69
+
|**Metric namespace**| Logical container where all metrics will be placed |`POWERTOOLS_METRICS_NAMESPACE`|`default_namespace`| Any string |`serverlessAirline`|`default_namespace`|
70
70
71
71
!!! tip
72
72
Use your application name or main service as the metric namespace to easily group all metrics
@@ -103,13 +103,13 @@ You can create metrics using the `addMetric` method, and you can create dimensio
0 commit comments