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: README.md
+6-4
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,10 @@
1
1
# AWS Lambda Powertools for TypeScript
2
2
3
-
A suite of utilities for AWS Lambda functions to ease the adoption of best practices such as tracing, structured logging, custom metrics, and more.
3
+
A suite of utilities for AWS Lambda functions to ease the adoption of best practices such as tracing, structured logging, custom metrics, and more.
4
+
4
5
You can use the library in both TypeScript and JavaScript code bases.
5
-
AWS Lambda Powertools for [Python](https://github.com/awslabs/aws-lambda-powertools-python) and AWS Lambda Powertools for [Java](https://github.com/awslabs/aws-lambda-powertools-java) are also available).
6
+
7
+
AWS Lambda Powertools for [Python](https://github.com/awslabs/aws-lambda-powertools-python) and AWS Lambda Powertools for [Java](https://github.com/awslabs/aws-lambda-powertools-java) are also available.
@@ -65,7 +67,7 @@ If you are interested in contributing to this project, please refer to our [Cont
65
67
## Roadmap
66
68
67
69
The roadmap of Powertools is driven by customers’ demand.
68
-
Help us prioritize upcoming functionalities or utilities by [upvoting existing RFCs and feature requests](https://github.com/awslabs/aws-lambda-powertools-typescript/issues), or [creating new ones[(https://github.com/awslabs/aws-lambda-powertools-typescript/issues/new/choose), in this GitHub repository.
70
+
Help us prioritize upcoming functionalities or utilities by [upvoting existing RFCs and feature requests](https://github.com/awslabs/aws-lambda-powertools-typescript/issues), or [creating new ones](https://github.com/awslabs/aws-lambda-powertools-typescript/issues/new/choose), in this GitHub repository.
69
71
70
72
## Connect
71
73
@@ -78,4 +80,4 @@ Credits for the Lambda Powertools idea go to [DAZN](https://github.com/getndazn)
78
80
79
81
## License
80
82
81
-
This library is licensed under the MIT-0 License. See the LICENSE file.
83
+
This library is licensed under the MIT-0 License. See the [LICENSE](https://github.com/awslabs/aws-lambda-powertools-typescript/blob/main/LICENSE) file.
Copy file name to clipboardExpand all lines: docs/core/logger.md
+38-32
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,13 @@ Logger provides an opinionated logger with output structured as JSON.
13
13
* Appending additional keys to structured logs at any point in time.
14
14
* Providing a custom log formatter (Bring Your Own Formatter) to output logs in a structure compatible with your organization’s Logging RFC.
15
15
16
+
<br />
17
+
18
+
<figure>
19
+
<imgsrc="../../media/logger_utility_showcase.png"loading="lazy"alt="Screenshot of the Amazon CloudWatch Console showing an example of error logged with various log attributes" />
The `Logger` utility must always be instantiated outside of the Lambda handler. In doing this, subsequent invocations processed by the same instance of your function can reuse these resources. This saves cost by reducing function run time. In addition, `Logger` can keep track of a cold start and inject the appropriate fields into logs.
35
+
The `Logger` utility must always be instantiated outside the Lambda handler. By doing this, subsequent invocations processed by the same instance of your function can reuse these resources. This saves cost by reducing function run time. In addition, `Logger` can keep track of a cold start and inject the appropriate fields into logs.
29
36
30
37
=== "handler.ts"
31
38
@@ -45,10 +52,10 @@ The library requires two settings. You can set them as environment variables, or
45
52
46
53
These settings will be used across all logs emitted:
**Logging level** | Sets how verbose Logger should be (INFO, by default). Supported values are: `DEBUG`, `INFO`, `WARN`, `ERROR` | `LOG_LEVEL` | `logLevel`
51
-
**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` | `serviceName`
|**Logging level**| Sets how verbose Logger should be (INFO, by default). Supported values are: `DEBUG`, `INFO`, `WARN`, `ERROR`|`LOG_LEVEL`|`logLevel`|
58
+
|**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`|`serviceName`|
52
59
53
60
For a **complete list** of supported environment variables, refer to [this section](./../index.md#environment-variables).
54
61
@@ -87,15 +94,15 @@ For a **complete list** of supported environment variables, refer to [this secti
87
94
88
95
Your Logger will include the following keys to your structured logging (default log formatter):
**level**: `string` | `INFO` | Logging level set for the Lambda function"s invocation
93
-
**message**: `string` | `Query performed to DynamoDB` | A descriptive, human-readable representation of this log item
94
-
**sampling_rate**: `float`| `0.1` | When enabled, it prints all the logs of a percentage of invocations, e.g. 10%
95
-
**service**: `string` | `serverlessAirline` | A unique name identifier of the service this Lambda function belongs to, by default `service_undefined`
96
-
**timestamp**: `string` | `2011-10-05T14:48:00.000Z` | Timestamp string in simplified extended ISO format (ISO 8601)
97
-
**xray_trace_id**: `string` | `1-5759e988-bd862e3fe1be46a994272793` | X-Ray Trace ID. This value is always presented in Lambda environment, whether [tracing is enabled](https://docs.aws.amazon.com/lambda/latest/dg/services-xray.html){target="_blank"} or not. Logger will always log this value.
98
-
**error**: `Object` | `{ name: "Error", location: "/my-project/handler.ts:18", message: "Unexpected error #1", stack: "[stacktrace]"}` | Optional - An object containing information about the Error passed to the logger
|**level**: `string`|`INFO`| Logging level set for the Lambda function"s invocation|
100
+
|**message**: `string`|`Query performed to DynamoDB`| A descriptive, human-readable representation of this log item|
101
+
|**sampling_rate**: `float`|`0.1`| When enabled, it prints all the logs of a percentage of invocations, e.g. 10%|
102
+
|**service**: `string`|`serverlessAirline`| A unique name identifier of the service this Lambda function belongs to, by default `service_undefined`|
103
+
|**timestamp**: `string`|`2011-10-05T14:48:00.000Z`| Timestamp string in simplified extended ISO format (ISO 8601)|
104
+
|**xray_trace_id**: `string`|`1-5759e988-bd862e3fe1be46a994272793`| X-Ray Trace ID. This value is always presented in Lambda environment, whether [tracing is enabled](https://docs.aws.amazon.com/lambda/latest/dg/services-xray.html){target="_blank"} or not. Logger will always log this value.|
105
+
|**error**: `Object`|`{ name: "Error", location: "/my-project/handler.ts:18", message: "Unexpected error #1", stack: "[stacktrace]"}`| Optional - An object containing information about the Error passed to the logger|
logger.info('This is an INFO log with some context');
173
+
174
+
};
175
+
```
170
176
171
177
In each case, the printed log will look like this:
172
178
@@ -189,7 +195,7 @@ In each case, the printed log will look like this:
189
195
190
196
#### Log incoming event
191
197
192
-
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`.
198
+
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`.
193
199
194
200
???+ warning
195
201
This is disabled by default to prevent sensitive info being logged
0 commit comments