Annotation Type 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 ElementsModifier and TypeOptional ElementDescriptionbooleanLogger is commonly initialized in the global scope.Json Pointer path to extract correlation id from.booleanSet to true if you want to log the exception thrown by the Lambda function handler.booleanSet 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 variablebooleanSet 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 variabledoubleSampling rate to change log level to DEBUG.
-
Element Details
-
logEvent
boolean logEventSet 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- Default:
false
-
logResponse
boolean logResponseSet 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- Default:
false
-
logError
boolean logErrorSet to true if you want to log the exception thrown by the Lambda function handler. It is already logged by AWS Lambda but with no context information. Setting this to true will log the exception and all the powertools additional fields, for more context.
Can also be configured with the 'POWERTOOLS_LOGGER_LOG_ERROR' environment variable- Default:
false
-
samplingRate
double samplingRateSampling rate to change log level to DEBUG. (values must be >=0.0, invalid input: '<'=1.0)- Default:
0.0
-
correlationIdPath
String correlationIdPathJson Pointer path to extract correlation id from.- See Also:
- Default:
""
-
clearState
boolean clearStateLogger is commonly initialized in the global scope. Due to Lambda Execution Context reuse, this means that custom keys can be persisted across invocations. Set this attribute to true if you want all custom keys to be deleted on each request.- Default:
false
-