@@ -100,6 +100,7 @@ public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatew
100
100
```
101
101
102
102
You can also explicitly log any incoming event using ` logEvent ` param.
103
+ Refer [ Override default object mapper] ( #override-default-object-mapper ) to customise what is logged.
103
104
104
105
<Note type = " warning" >
105
106
This is disabled by default to prevent sensitive info being logged.
@@ -165,6 +166,42 @@ public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatew
165
166
}
166
167
```
167
168
169
+ ## Override default object mapper
170
+
171
+ You can optionally choose to override default object mapper which is used to serialize lambda function events. You might
172
+ want to supply custom object mapper in order to control how serialisation is done, for example, when you want to log only
173
+ specific fields from received event due to security.
174
+
175
+ ``` java:title=App.java
176
+ package helloworld ;
177
+
178
+ import org.apache.logging.log4j.LogManager ;
179
+ import org.apache.logging.log4j.Logger ;
180
+ import software.amazon.lambda.logging.LoggingUtils ;
181
+ import software.amazon.lambda.logging.Logging ;
182
+ ...
183
+
184
+ /**
185
+ * Handler for requests to Lambda function.
186
+ */
187
+ public class App implements RequestHandler<APIGatewayProxyRequestEvent , APIGatewayProxyResponseEvent > {
188
+
189
+ Logger log = LogManager . getLogger();
190
+
191
+ // highlight-start
192
+ static {
193
+ ObjectMapper objectMapper = new ObjectMapper ();
194
+ LoggingUtils . defaultObjectMapper(objectMapper);
195
+ }
196
+ // highlight-end
197
+
198
+ @Logging (logEvent = true )
199
+ public APIGatewayProxyResponseEvent handleRequest (final APIGatewayProxyRequestEvent input , final Context context ) {
200
+ ...
201
+ }
202
+ }
203
+ ```
204
+
168
205
## Sampling debug logs
169
206
170
207
You can dynamically set a percentage of your logs to ** DEBUG** level via env var ` POWERTOOLS_LOGGER_SAMPLE_RATE ` or
0 commit comments