ConsoleAppender: support JLine's org.jline.jansi.AnsiConsole for <withJansi> - #1050
Merged
ceki merged 1 commit intoJul 24, 2026
Merged
Conversation
…ansi>
Jansi was migrated from FuseSource (org.fusesource.jansi) to JLine
(org.jline.jansi), which changed the package of AnsiConsole. Because
ConsoleAppender loaded the FuseSource class name by reflection, <withJansi>
silently fell back to the plain stream ("Failed to create AnsiPrintStream",
ClassNotFoundException: org.fusesource.jansi.AnsiConsole) for users who now
have only the JLine Jansi artifact on the classpath.
Probe the JLine coordinates first and fall back to the legacy FuseSource
ones, so <withJansi> keeps working with either artifact.
Fixes qos-ch#1043
Signed-off-by: seonwoo_jung <79202163+seonwooj0810@users.noreply.github.com>
Member
|
@seonwooj0810 Thank you for this PR. Its conciseness was a plus. |
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.
Fixes #1043
Root cause
Jansi was migrated from FuseSource (
org.fusesource.jansi) to JLine (org.jline.jansi), which changed the package ofAnsiConsole.ConsoleAppender.wrapWithJansi(...)loaded the FuseSource class name by reflection (org.fusesource.jansi.AnsiConsole), so for users who now have only the JLine Jansi artifact on the classpath,<withJansi>silently degrades to the plain stream:Change
ConsoleAppendernow probes an ordered list of candidate class names — JLineorg.jline.jansi.AnsiConsolefirst, then the legacy FuseSourceorg.fusesource.jansi.AnsiConsole— via a smallloadAnsiConsoleClass(ClassLoader)helper. JLine repackages the same Jansi 2 API (out()/err()/systemInstall()), so the existing reflective method lookup is unchanged.This matches the approach suggested in the issue thread ("try the new class name and fall back to the old one").
Tests
ConsoleAppenderJansiClassResolutionTest(dependency-free, uses a customClassLoaderto simulate each environment): verifies JLine is preferred when both are present, falls back to FuseSource when JLine is absent, and throwsClassNotFoundExceptionwhen neither is available. These fail against the old hard-coded lookup in a JLine-only environment and pass after the change.JansiConsoleAppenderTest(FuseSource on the classpath) still passes, confirming the legacy path is preserved.Verification done: built and ran
mvn -pl logback-core test -Dtest=ConsoleAppenderJansiClassResolutionTest(3 passed) andmvn -pl logback-core-blackbox test -Dtest=JansiConsoleAppenderTest(2 passed) on JDK 25 with--release 17.Note: the JPMS
module-info/ OSGiImport-Packagedescriptors still referenceorg.fusesource.jansionly; I kept this PR to the runtime reflective lookup to stay minimal, but happy to add JLine to those optional requirements as a follow-up if desired.