@@ -50,6 +50,8 @@ logger.error('This is an ERROR log');
50
50
51
51
### Capturing Lambda context info
52
52
53
+ Without decorators:
54
+
53
55
``` typescript
54
56
// Environment variables set for the Lambda
55
57
process .env .LOG_LEVEL = ' WARN' ;
@@ -108,6 +110,51 @@ const lambdaHandler: Handler = async (event, context) => {
108
110
</details >
109
111
110
112
113
+ With decorators:
114
+
115
+ ``` typescript
116
+ // Environment variables set for the Lambda
117
+ process .env .LOG_LEVEL = ' INFO' ;
118
+ process .env .POWERTOOLS_SERVICE_NAME = ' hello-world' ;
119
+
120
+ const logger = new Logger ();
121
+
122
+ class Lambda implements LambdaInterface {
123
+
124
+ @logger .injectLambdaContext ()
125
+ public handler<TEvent , TResult >(_event : TEvent , _context : Context , _callback : Callback <TResult >): void | Promise <TResult > {
126
+
127
+ logger .info (' This is an INFO log with some context' );
128
+
129
+ }
130
+
131
+ }
132
+
133
+ new Lambda ().handler (dummyEvent , dummyContext , () => console .log (' Lambda invoked!' ));
134
+
135
+ ```
136
+
137
+ <details >
138
+ <summary >Click to expand and see the logs outputs</summary >
139
+
140
+ ``` bash
141
+
142
+ {
143
+ aws_request_id: ' c6af9ac6-7b61-11e6-9a41-93e8deadbeef' ,
144
+ lambda_function_arn: ' arn:aws:lambda:eu-central-1:123456789012:function:Example' ,
145
+ lambda_function_memory_size: 128,
146
+ lambda_function_name: ' foo-bar-function' ,
147
+ level: ' INFO' ,
148
+ message: ' This is an INFO log with some context' ,
149
+ service: ' hello-world' ,
150
+ timestamp: ' 2021-03-17T08:25:41.198Z' ,
151
+ xray_trace_id: ' abcdef123456abcdef123456abcdef123456'
152
+ }
153
+
154
+ ```
155
+ </details >
156
+
157
+
111
158
### Appending additional keys
112
159
113
160
``` typescript
0 commit comments