T-1365 Keep the appender running while the JVM shuts down - #34
Merged
Merged
Conversation
Spring Boot and Quarkus keep logging while they shut down and stop logback at the very end. Since 0.3.8 the appender's own JVM shutdown hook stops the appender as soon as the JVM starts shutting down, so those lines are rejected. FrameworkApp reproduces that in a child JVM. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The shutdown hook now only sends what is queued, after waiting for a flush in progress, instead of stopping the appender. Lines logged afterwards by the application's own shutdown are queued as usual and sent when the framework (or logback's <shutdownHook>) stops logback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PetrHeinz
marked this pull request as ready for review
September 29, 2026 10:21
PetrHeinz
added a commit
that referenced
this pull request
Sep 29, 2026
Merging main brought in flushQueue() as #34 added it, next to the version this branch replaces it with, and the class did not compile. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The JVM shutdown hook added in #31 calls
stop()as soon as the JVM starts shutting down. The JVM runs all shutdown hooks at the same time, so anything the application logs after that moment is rejected by logback ("Attempted to append to non started appender [Logtail]", only visible with a status listener). Frameworks log a lot at exactly that point and stop logback themselves only at the very end: Spring Boot's logging shutdown handler and the Quarkus logback extension's last shutdown task both callLoggerContext.stop(), and so does logback's own<shutdownHook>.Measured end to end with 0.3.8 against a real source, SIGTERM one second into a four-second request:
ContextClosedEventlistener's line, "Commencing graceful shutdown", the in-flight request's last line, "Graceful shutdown complete" and the@PreDestroyline, so every rolling deploy loses its shutdown logs.ShutdownEventobserver's line.<shutdownHook>plus a<delay>lost the line its own shutdown hook logged, which 0.3.7 still delivered.The hook now only sends what is queued, after waiting for a flush in progress, and leaves the appender running. Whatever is logged afterwards is sent when the framework or logback's hook stops logback, and a JVM that exits without anyone stopping logback still gets its queued logs sent as before. The same scenarios with this change: Spring Boot 19 of 19 lines, the logback
<delay>case 4 of 4, and return frommain,System.exit, SIGTERM and a 25,000-line backlog all still delivered in full.The first commit only adds
testLogsWrittenWhileAFrameworkShutsDownAreSentWhenItStopsLogbackand is expected to fail on CI: a child JVM whose own shutdown hook logs a line and then stops logback, like Spring Boot does. The existing exit test moved onto the same helper.🤖 Generated with Claude Code