skip to Main Content

I want the log produced by the java runtime in an AWS lambda function to be in JSON format.

I’m talking about logs like these:

2022-07-27T19:30:21.094+03:00   START RequestId: 09e6e95c-5b1f-53c0-8483-b207312166be Version: $LATEST
2022-07-27T19:30:37.640+03:00   SLF4J: Class path contains multiple SLF4J bindings.
2022-07-27T19:31:03.536+03:00   END RequestId: 09e6e95c-5b1f-53c0-8483-b207312166be
2022-07-27T19:31:03.536+03:00   REPORT RequestId: 09e6e95c-5b1f-53c0-8483-b207312166be Duration: 42441.58 ms Billed Duration: 42442 ms Memory Size: 512 MB Max Memory Used: 226 MB

2

Answers


  1. You cannot alter the format of the START, END, or REPORT log lines. These are produced by the Lambda service.

    Login or Signup to reply.
  2. In AWS Lambda, when you write a Java Lambda function, you have two options for logging.

    Add log4j2 propety in your lambda class path

    log4j2.properties file to use the JSON Template Layout:

           log4j.appender.stdout=org.apache.log4j.ConsoleAppender
           log4j.appender.stdout.encoding=UTF-8
           log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
           log4j.appender.stdout.layout.ConversionPattern={"debug_level":"%p","debug_timestamp":"%d{ISO8601}","debug_thread":"%t","debug_file":"%F", "debug_line":"%L","debug_message":"%m"}%n
    

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search