Annotation Type Logging


@Retention(RUNTIME) @Target(METHOD) public @interface Logging
Logging is used to signal that the annotated method should be extended with Logging functionality.

Logging provides an opinionated logger with output structured as JSON.

Logging should be used with the handleRequest method of a class which implements either com.amazonaws.services.lambda.runtime.RequestHandler or com.amazonaws.services.lambda.runtime.RequestStreamHandler.

By default Logging will load the following keys and values from the Lambda com.amazonaws.services.lambda.runtime.Context

  • function_name
  • function_version
  • function_arn
  • function_memory_size
  • function_request_id

By default Logging will also create keys for:

  • cold_start - True if this is the first invocation of this Lambda execution environment; else False
  • service - The value of the 'POWER_TOOLS_SERVICE_NAME' environment variable or 'service_undefined'
  • sampling_rate - The value of the 'POWERTOOLS_LOGGER_SAMPLE_RATE' environment variable or value of sampling_rate field or 0. Valid value is from 0.0 to 1.0. Value outside this range is silently ignored.

These keys and values will be joined with the existing Log4J log event and written as JSON.

The data and time of the log event will be written using DateTimeFormatter.ISO_ZONED_DATE_TIME

By default Logging will not log the event which has trigger the invoke of the Lambda function. This can be enabled using @Logging(logEvent = true).

To append additional keys to each log entry you can either use MDC.put(String, String) or StructuredArguments

  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    Logger is commonly initialized in the global scope.
    Json Pointer path to extract correlation id from.
    boolean
    Set to true if you want to log the exception thrown by the Lambda function handler.
    boolean
    Set to true if you want to log the event received by the Lambda function handler.
    Can also be configured with the 'POWERTOOLS_LOGGER_LOG_EVENT' environment variable
    boolean
    Set to true if you want to log the response sent by the Lambda function handler.
    Can also be configured with the 'POWERTOOLS_LOGGER_LOG_RESPONE' environment variable
    double
    Sampling rate to change log level to DEBUG.