You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Log multi-line output of the managed Keycloak server as a single record - #54830
The managed server's console output was forwarded to the test log line by line, and every line that wasn't a record header was logged at INFO. The test log filter drops INFO output of the managed server, so only the first line of an error remained in the CI output and the stack trace and root cause were lost.
The managed server now starts with JSON console logging in the ECS format, and each record is forwarded as a single log statement with its original level.
Rationale
Parsing JSON avoids buffering, timers and flushing heuristics that would be needed to reassemble multi-line plain-text records, and it adds no delay when the server stops.
The ECS format was chosen as its field names (log.level, message, error.stack_trace, log.logger) are documented.
Decisions
The server is started with KC_LOG_CONSOLE_OUTPUT=json and KC_LOG_CONSOLE_JSON_FORMAT=ecs, set only if not already defined in the environment.
Lines starting with { are treated as JSON records; all other lines (for example output before logging is initialized) are logged as plain INFO lines, so no output is lost. A line starting with { that fails to parse is logged as a plain INFO line as well.
If a record has error.stack_trace, it is appended to the message so that message and stack trace are one statement.
Records are logged under managed.keycloak.<original logger name> instead of managed.keycloak. Child loggers inherit the level of managed.keycloak, so the configured test log filter behaves as before, and the origin of a record stays visible. This follows the existing managed.keycloak.<index> naming of the clustered server.
The startup detection ("started in") now reads the JSON message field.
Added ManagedServerLogTest, which attaches a handler to managed.keycloak, logs an error with a nested cause on the server, and asserts a single record with the original level containing the stack trace and Caused by. It is skipped when a server other than distribution is selected.
Assumptions
The default test server is distribution (first registered supplier), so the new test runs in the regular "Test Framework" CI job.
The default JSON field names of the ECS format are stable, in particular error.stack_trace and log.level.
Server output not formatted as a record is not expected to continue a previous record.
Verification
Ran KC_TEST_SERVER=distribution ./mvnw test -pl test-framework/tests -Dtest=ManagedServerLogTest locally.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unresolved log-format handling can suppress WARN/ERROR records, discard stdout content, and delay startup detection, while the test can incorrectly run against the embedded supplier.
This PR updates the test framework’s managed distribution server logging to keep error messages and stack traces together, making CI failures easier to diagnose.
Changes:
Defaults managed-server console output to ECS JSON and forwards each record with its original level and logger name.
Adds an integration test for forwarding a stack trace and nested cause as one record.
Force ECS JSON output, forward non-record JSON lines unchanged, detect startup on plain lines, and honor supplier filters in the test assumption.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Alexander Schwartz <alexander.schwartz@ibm.com>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The stdout-dependent test can fail after 30 seconds when server reuse is enabled because the reused server does not deliver console logs to the current JVM.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Skip stdout-dependent test when reusing an existing server
With KC_TEST_SERVER_REUSE=true, a subsequent test run can reuse an already-running distribution: DistributionKeycloakServer.start() returns before creating an OutputHandler, so this JVM never receives its console logs and the test fails after 30 seconds. Skip this stdout-dependent test when reuse is enabled, or ensure it starts a fresh server.
The reason will be displayed to describe this comment to others. Learn more.
🟢 Approval recommended
No active review issues are reported for the managed-server logging changes.
No open issues 🎉
Review effort: Balanced
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
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.
Closes #54829
The managed server's console output was forwarded to the test log line by line, and every line that wasn't a record header was logged at INFO. The test log filter drops INFO output of the managed server, so only the first line of an error remained in the CI output and the stack trace and root cause were lost.
The managed server now starts with JSON console logging in the ECS format, and each record is forwarded as a single log statement with its original level.
Rationale
Parsing JSON avoids buffering, timers and flushing heuristics that would be needed to reassemble multi-line plain-text records, and it adds no delay when the server stops.
The ECS format was chosen as its field names (
log.level,message,error.stack_trace,log.logger) are documented.Decisions
KC_LOG_CONSOLE_OUTPUT=jsonandKC_LOG_CONSOLE_JSON_FORMAT=ecs, set only if not already defined in the environment.{are treated as JSON records; all other lines (for example output before logging is initialized) are logged as plain INFO lines, so no output is lost. A line starting with{that fails to parse is logged as a plain INFO line as well.error.stack_trace, it is appended to the message so that message and stack trace are one statement.managed.keycloak.<original logger name>instead ofmanaged.keycloak. Child loggers inherit the level ofmanaged.keycloak, so the configured test log filter behaves as before, and the origin of a record stays visible. This follows the existingmanaged.keycloak.<index>naming of the clustered server.messagefield.ManagedServerLogTest, which attaches a handler tomanaged.keycloak, logs an error with a nested cause on the server, and asserts a single record with the original level containing the stack trace andCaused by. It is skipped when a server other thandistributionis selected.Assumptions
distribution(first registered supplier), so the new test runs in the regular "Test Framework" CI job.error.stack_traceandlog.level.Verification
Ran
KC_TEST_SERVER=distribution ./mvnw test -pl test-framework/tests -Dtest=ManagedServerLogTestlocally.