|
| 1 | +/* |
| 2 | + * Copyright 2023 Amazon.com, Inc. or its affiliates. |
| 3 | + * Licensed under the Apache License, Version 2.0 (the |
| 4 | + * "License"); you may not use this file except in compliance |
| 5 | + * with the License. You may obtain a copy of the License at |
| 6 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + * Unless required by applicable law or agreed to in writing, software |
| 8 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | + * See the License for the specific language governing permissions and |
| 11 | + * limitations under the License. |
| 12 | + * |
| 13 | + */ |
| 14 | + |
| 15 | +package software.amazon.lambda.powertools.logging.internal.handler; |
| 16 | + |
| 17 | +import com.amazonaws.services.lambda.runtime.Context; |
| 18 | +import com.amazonaws.services.lambda.runtime.RequestHandler; |
| 19 | +import com.amazonaws.services.lambda.runtime.events.SQSEvent; |
| 20 | +import com.fasterxml.jackson.core.JsonProcessingException; |
| 21 | +import org.slf4j.Logger; |
| 22 | +import org.slf4j.LoggerFactory; |
| 23 | +import software.amazon.lambda.powertools.logging.Logging; |
| 24 | +import software.amazon.lambda.powertools.utilities.JsonConfig; |
| 25 | + |
| 26 | +public class PowertoolsJsonMessage implements RequestHandler<SQSEvent.SQSMessage, String> { |
| 27 | + private final Logger LOG = LoggerFactory.getLogger(PowertoolsJsonMessage.class); |
| 28 | + |
| 29 | + @Override |
| 30 | + @Logging(clearState = true) |
| 31 | + public String handleRequest(SQSEvent.SQSMessage input, Context context) { |
| 32 | + try { |
| 33 | + LOG.debug(JsonConfig.get().getObjectMapper().writeValueAsString(input)); |
| 34 | + LOG.debug("{}", input.getMessageId()); |
| 35 | + LOG.warn("Message body = {} and id = \"{}\"", input.getBody(), input.getMessageId()); |
| 36 | + } catch (JsonProcessingException e) { |
| 37 | + throw new RuntimeException(e); |
| 38 | + } |
| 39 | + return input.getMessageId(); |
| 40 | + } |
| 41 | +} |
0 commit comments