A simple opinionated structured logger for AWS Lambda
To provide a simple and easy to use structured logger specifically for use with AWS Lambda.
The following example usage:
import net.sailes.lambda.logger.Logger;
import net.sailes.lambda.logger.LoggerFactory;
public class PaymentHandler implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent event, Context context) {
Logger logger = LoggerFactory.getLogger();
logger.addContextKeys(context);
logger.info("Collecting Payment");
...
}
}
Produces a single line JSON formatted output (displayed in multi-line for readability)
{
"timestamp":"2020-08-09T11:52:34.290Z",
"service":"Payment Service",
"message":"Collecting Payment",
"coldStart":true,
"functionName":"example-HelloWorldFunction-1P1Z6B39FLU73",
"functionVersion":"1.0.0",
"functionArn":"arn:aws:lambda:eu-west-1:012345678910:function:example-HelloWorldFunction-1P1Z6B39FLU73",
"functionMemorySize":512,
"functionRequestId":"899856cb-83d1-40d7-8611-9e78f15f32f4"
}
<dependency>
<groupId>net.sailes</groupId>
<artifactId>lambda-structured-logger</artifactId>
<version>0.2.0</version>
</dependency>
To use the cold start tracking functionality please use the LoggerFactory.getLogger()
method.
Environment Variables
Name | Description | Default |
---|---|---|
SERVICE_NAME |
Friendly name for your function | service_undefined |