Summary
We are excited to announce a new feature in Logger: Logger buffering. This new feature allows you to buffer logs for a specific invocation, and flush them automatically on error or manually as needed.
We also added GraalVM support for CloudFormation and Idempotency utilities, expanding native compilation capabilities for better performance and reduced cold start times.
⭐️ Thanks to @ConnorKirk, @aryannikhil, and @kjswaruph for their first-time contributions to this release!
New Log Buffering feature
You can now enable log buffering by configuring the BufferingAppender
in your logging configuration. This feature allows you to:
- Buffer logs at the
WARNING
,INFO
, andDEBUG
levels - Automatically flush logs on error or manually as needed
- Reduce CloudWatch costs by decreasing the number of emitted log messages
public class PaymentFunction implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
private static final Logger LOGGER = LoggerFactory.getLogger(PaymentFunction.class);
@Logging
public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEvent input, final Context context) {
LOGGER.debug("Processing payment"); // this is buffered
LOGGER.info("Payment validation complete"); // this is not buffered
LOGGER.error("Payment failed"); // this will flush the buffer automatically
return new APIGatewayProxyResponseEvent().withStatusCode(500);
}
}
Configuration options
Log buffering is configured through your logging framework configuration (Log4j2 or Logback) using the BufferingAppender
:
Option | Description | Default |
---|---|---|
maxBytes |
Maximum size of the buffer in bytes | 20480 |
bufferAtVerbosity |
Minimum log level to buffer (more verbose levels are also buffered) | DEBUG |
flushOnErrorLog |
Whether to flush buffer when an error is logged | true |
When log buffering is enabled, you can use the @Logging
annotation with flushBufferOnUncaughtError = true
to automatically flush the buffer when an uncaught exception occurs. This enables you to have detailed logs from your application when you need them the most.
Here is an example log4j2.xml
configuration:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="JsonAppender" target="SYSTEM_OUT">
<JsonTemplateLayout eventTemplateUri="classpath:LambdaJsonLayout.json" />
</Console>
<BufferingAppender name="BufferedJsonAppender"
maxBytes="20480"
bufferAtVerbosity="DEBUG"
flushOnErrorLog="true">
<AppenderRef ref="JsonAppender"/>
</BufferingAppender>
</Appenders>
<Loggers>
<Root level="DEBUG">
<AppenderRef ref="BufferedJsonAppender"/>
</Root>
</Loggers>
</Configuration>
Buffering FAQs
Q: Does the buffer persist across Lambda invocations?
A: No. Each Lambda invocation has its own buffer. The buffer initializes when the Lambda function is invoked and clears after function completion or manual flushing.
Q: Are my logs buffered during cold starts?
A: No. We never buffer logs during cold starts to ensure all logs from this phase are immediately available for debugging.
Q: How can I prevent log buffering from consuming excessive memory?
A: You can limit the size of the buffer by setting the maxBytes
option in the BufferingAppender
configuration. This will ensure that the buffer does not grow indefinitely and consume excessive memory.
Q: What happens if the log buffer reaches its maximum size?
A: Older logs are removed from the buffer to make room for new logs. This means that if the buffer is full, you may lose some logs if they are not flushed before the buffer reaches its maximum size. When this happens, we emit a warning when flushing the buffer to indicate that some logs have been dropped.
Q: What timestamp is used when I flush the logs?
A: The timestamp preserves the original time when the log record was created. If you create a log record at 11:00:10 and flush it at 11:00:25, the log line will retain its original timestamp of 11:00:10.
Q: What happens if I try to add a log line that is bigger than max buffer size?
A: The log will be emitted directly to standard output and not buffered. When this happens, we emit a warning to indicate that the log line was too big to be buffered.
Q: What happens if Lambda times out without flushing the buffer?
A: Logs that are still in the buffer will be lost. If you are using the log buffer to log asynchronously, you should ensure that the buffer is flushed before the Lambda function times out. You can do this by calling the PowertoolsLogging.flushBuffer()
method at the end of your Lambda function.
Changes
- chore(ci): bump version to 2.4.0 (#2139) by @github-actions[bot]
- chore(ci): Set mockito SNAPSHOT version only for Graal profiles. (#2138) by @phipag
- chore(ci): Do not use Mockito SNAPSHOT version for release. (#2137) by @phipag
- chore(ci): Skip maven deployment for e2e test handlers. (#2131) by @phipag
- chore(ci): Fix circular dependency in dynamodb-local and maven packaging phases (#2129) by @phipag
- chore: bump org.yaml:snakeyaml from 2.4 to 2.5 (#2111) by @dependabot[bot]
- chore: bump io.github.ascopes:protobuf-maven-plugin from 3.8.1 to 3.9.0 (#2114) by @dependabot[bot]
- chore: bump aws.sdk.version from 2.32.31 to 2.33.1 (#2115) by @dependabot[bot]
- chore: bump graalvm/setup-graalvm from 1.3.5 to 1.3.6 (#2116) by @dependabot[bot]
- chore: bump software.amazon.awscdk:aws-cdk-lib from 2.213.0 to 2.214.0 (#2117) by @dependabot[bot]
- chore: bump aws-actions/configure-aws-credentials from 4.3.1 to 5.0.0 (#2120) by @dependabot[bot]
- chore: bump com.github.spotbugs:spotbugs-maven-plugin from 4.9.4.0 to 4.9.4.2 (#2125) by @dependabot[bot]
- chore: bump github/codeql-action from 3.30.0 to 3.30.1 (#2126) by @dependabot[bot]
- chore: bump squidfunk/mkdocs-material from
1a4e939
to209b62d
in /docs (#2127) by @dependabot[bot] - feat(logging): Log buffering support for Logj42 and Logback (#2103) by @phipag
- docs: Update AWS copyright notice (#2119) by @phipag
- test(metrics): Improve testability of
@FlushMetrics
annotation (#2112) by @phipag - chore: bump jackson.version from 2.19.2 to 2.20 (#2097) by @dependabot[bot]
- chore: bump dev.aspectj:aspectj-maven-plugin from 1.13.1 to 1.14.1 (#2099) by @dependabot[bot]
- chore: bump aws.sdk.version from 2.32.26 to 2.32.31 (#2098) by @dependabot[bot]
- chore: bump github/codeql-action from 3.29.11 to 3.30.0 (#2106) by @dependabot[bot]
- chore: bump software.amazon.awscdk:aws-cdk-lib from 2.212.0 to 2.213.0 (#2100) by @dependabot[bot]
- chore: bump org.apache.maven.plugins:maven-compiler-plugin from 3.11.0 to 3.14.0 (#2094) by @dependabot[bot]
- chore: bump actions/checkout from 4.2.2 to 5.0.0 (#2087) by @dependabot[bot]
- docs: Update docs introduction (#2107) by @ConnorKirk
- chore: bump org.apache.logging.log4j:log4j-transform-maven-shade-plugin-extensions from 0.1.0 to 0.2.0 (#2088) by @dependabot[bot]
- chore: bump io.github.ascopes:protobuf-maven-plugin from 3.8.0 to 3.8.1 (#2085) by @dependabot[bot]
- chore: bump com.github.spotbugs:spotbugs-maven-plugin from 4.9.3.2 to 4.9.4.0 (#2084) by @dependabot[bot]
- chore: bump sam/build-java21 from
6ad1664
to853ac90
in /powertools-e2e-tests/src/test/resources/docker (#2083) by @dependabot[bot] - feat(graalvm): GraalVM support for powertools-cloudformation (#2090) by @phipag
- chore: bump aws.sdk.version from 2.32.30 to 2.32.31 (#2093) by @dependabot[bot]
- chore: bump actions/dependency-review-action from 4.7.2 to 4.7.3 (#2092) by @dependabot[bot]
- feat: Support CRaC priming of powertools validation (#2081) by @kjswaruph
- feat(graalvm): GraalVM support for Idempotency utility (#2080) by @phipag
- chore: bump aws.sdk.version from 2.32.28 to 2.32.30 (#2089) by @dependabot[bot]
- chore(gitignore): add .kiro, .claude, .amazonq to prevent deletion (#2078) by @aryannikhil
- chore(ci): Run unit tests for GraalVM as well during build. (#2047) by @phipag
- chore(ci): Fix issue where docs were released with old version during release (#2076) by @phipag
- chore: bump sam/build-java21 from
44e9166
to6ad1664
in /powertools-e2e-tests/src/test/resources/docker (#2075) by @dependabot[bot] - chore: bump squidfunk/mkdocs-material from
405aeb6
to1a4e939
in /docs (#2074) by @dependabot[bot] - chore: bump github/codeql-action from 3.29.10 to 3.29.11 (#2073) by @dependabot[bot]
- chore: bump log4j.version from 2.25.1 to 2.25.1 (#2072) by @dependabot[bot]
- chore: bump org.apache.maven.plugins:maven-shade-plugin from 3.5.0 to 3.6.0 (#2071) by @dependabot[bot]
- chore: bump org.graalvm.buildtools:native-maven-plugin from 0.10.6 to 0.11.0 (#2070) by @dependabot[bot]
- chore: bump com.amazonaws:aws-lambda-java-runtime-interface-client from 2.8.2 to 2.8.3 (#2069) by @dependabot[bot]
- chore: bump aws.sdk.version from 2.32.2 to 2.32.28 (#2068) by @dependabot[bot]
- chore: bump actions/setup-java from 4.7.1 to 5.0.0 (#2067) by @dependabot[bot]
- chore: bump software.amazon.awscdk:aws-cdk-lib from 2.211.0 to 2.212.0 (#2066) by @dependabot[bot]
- chore: bump org.apache.maven.plugins:maven-javadoc-plugin from 3.11.2 to 3.11.3 (#2065) by @dependabot[bot]
- chore: bump aws.sdk.version from 2.32.25 to 2.32.27 (#2064) by @dependabot[bot]
- chore(ci): Add powertools-e2e-tests/handlers as module to capture it in GitHub actions version upgrades. (#2063) by @phipag
- chore: bump squidfunk/mkdocs-material from
bb7b015
to405aeb6
in /docs (#2058) by @dependabot[bot] - chore: bump org.apache.maven.plugins:maven-javadoc-plugin from 3.11.2 to 3.11.3 (#2059) by @dependabot[bot]
- chore: bump io.github.ascopes:protobuf-maven-plugin from 3.7.0 to 3.8.0 (#2057) by @dependabot[bot]
- chore: bump github/codeql-action from 3.29.9 to 3.29.10 (#2056) by @dependabot[bot]
- chore: bump actions/dependency-review-action from 4.7.1 to 4.7.2 (#2055) by @dependabot[bot]
- chore: bump aws.sdk.version from 2.32.23 to 2.32.25 (#2054) by @dependabot[bot]
- chore: bump aws.sdk.version from 2.32.19 to 2.32.26 (#2060) by @dependabot[bot]
- fix(ci): Update branch protection output (#2053) by @sthulb
- chore: bump actions/checkout from 4.2.2 to 5.0.0 (#2036) by @dependabot[bot]
- chore: bump aws.sdk.version from 2.32.22 to 2.32.23 (#2048) by @dependabot[bot]
- chore: bump com.google.protobuf:protobuf-java from 4.31.1 to 4.32.0 (#2050) by @dependabot[bot]
- chore: bump aws.sdk.version from 2.32.21 to 2.32.22 (#2046) by @dependabot[bot]
- docs: update readme (#2045) by @dreamorosi
- chore(ci): Remove non-PR triggers for verify dependencies workflow. (#2044) by @phipag
- chore: bump software.amazon.awscdk:aws-cdk-lib from 2.210.0 to 2.211.0 (#2042) by @dependabot[bot]
- chore: bump aws.sdk.version from 2.32.18 to 2.32.21 (#2041) by @dependabot[bot]
- chore: bump org.apache.maven.plugins:maven-deploy-plugin from 3.1.2 to 3.1.4 (#2040) by @dependabot[bot]
- chore: bump github/codeql-action from 3.29.8 to 3.29.9 (#2038) by @dependabot[bot]
- chore: bump dev.aspectj:aspectj-maven-plugin from 1.14 to 1.14.1 (#2037) by @dependabot[bot]
- chore(ci): bump version to 2.3.0 (#2034) by @github-actions[bot]
📜 Documentation updates
This release was made possible by the following contributors:
@ConnorKirk, @aryannikhil, @dreamorosi, @kjswaruph, @phipag, @sthulb