Repository navigation
CAMEL-26937: camel-jbang - the short commands start without log4j, and print without a JLine terminal when piped - #30016
Conversation
…d print without a JLine terminal when piped - The CLI has an SLF4J provider of its own (CliLoggerProvider, installed by the main method of the launcher and of JBang): its loggers log nothing until the CLI configures the logging (RuntimeUtil.configureLog, camel infra run), and then log with log4j. A command that turns the logging off, such as camel ps, get or doc, no longer starts log4j only because a class of Camel creates a static logger. Log4j already logged nothing until the CLI configured it (CAMEL-26429), so the commands log as before. - Without a terminal a command leaves out the ANSI colors of printColored itself, as the console would, instead of asking the console, which builds a JLine system terminal to find that out. -Djansi.mode still goes to the console. Measured with the launcher on JDK 25, warm CDS, best of 7: camel ps 237 -> 140 ms, get route 259 -> 170 ms, doc timer 245 -> 150 ms, camel log (piped) 439 -> 347 ms. The debug log of camel run is the same, line for line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
gnodet-bot
left a comment
There was a problem hiding this comment.
LGTM. Concurrency design is correct (DCL with volatile on delegate/delegate, synchronized (CliLogging.class) throughout, idempotent delegateTo()). ANSI regex matches Jansi's CSI-only output. The deferred path in RuntimeUtil.configureLog() correctly skips loggingConfigured() for silent commands, leaving them with no-op SubstituteLoggers. InfraRun's independent loggingConfigured() call is safe because delegateTo() guards on delegate == null. Tests are thorough — particularly LauncherStartupLoggingTest.aCommandWithTheLoggingOffDoesNotStartLog4j() which validates the actual class-loading improvement.
One low-severity doc nit inline.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
|
🧪 CI tested the following changed modules:
🔬 Scalpel shadow comparison — Scalpel: 6 of 726 tested, 7 compile-only — current: 6 all testedMaveniverse Scalpel detected 6 affected modules (current approach: 6). Skip-tests mode would test 6 modules (3 direct + 5 downstream), skip tests for 7 (generated code, meta-modules) Modules Scalpel would test (6)
Modules with tests skipped (7)
💡 Manual integration tests recommended:
All tested modules (15 modules, 3m 19s total)Total reactor time: 3m 19s
Top 20 slowest modules:
|
…er sentences (review) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
JIRA: CAMEL-26937, items 1 and 2.
What changes
No log4j for the commands that do not log. Most commands (
camel ps,get,doc,cmd ...) turn the logging off. Since CAMEL-26429, log4j configures itself only when something logs. But a static slf4j logger of a Camel class (FileUtilforcamel ps) still bound slf4j to log4j, and that started log4j-core: about 690 log4j classes and 170 Jackson 2 classes, only to log nothing. The off path ofRuntimeUtilalso started it, to ask whether it was configured.The CLI now has an slf4j provider of its own,
CliLoggerProvider. The main method of the launcher (CamelLauncher) and of JBang (CamelJBangMain.run(String...)) installs it through theslf4j.providersystem property, unless one is already set. Its loggers are slf4jSubstituteLoggers that log nothing until the CLI configures the logging (RuntimeUtil.configureLog,camel infra run); from then on they log with the provider on the classpath (log4j). The MDC adapter and marker factory are passed on lazily, so binding slf4j does not start log4j either. Log4j already logged nothing before that point, so every command logs as before. The tests of the commands callexecuteand keep the normal log4j binding.No JLine terminal when the output is piped.
printColoredaskedAnsiConsoleto strip the colors, which builds a JLine system terminal (TerminalBuilder,FfmTerminalProvider) just to find out that there is no terminal. Without a terminal the command now leaves out the ANSI codes itself, unless-Djansi.modeis set. Output in a terminal is unchanged.Measured
Launcher built from main today, JDK 25, warm CDS, best of 7, scratch home:
camel pscamel get routecamel doc timercamel log <name> --follow=false(piped)Classes loaded by
camel psgo from 3,383 to 1,764, with no log4j or Jackson 2 classes.camel run --logging-level=debugprints the same 556 lines as main, apart from hash codes and timings. A foreground run, a background run (log file,camel log), and--logging-categoryall log as before.Tests
CliLoggerProviderTest: a logger logs nothing before the logging is configured; once configured it logs with the provider on the classpath, whether it was created before or after; choosing the provider does not start log4j; the MDC is the provider's.CliLoggingTest: slf4j may choose the provider before or after the CLI configures the logging.LauncherStartupLoggingTest:camel doc timerthrough the launcher main loads the CLI's provider and no log4j class. It fails without the change (554 log4j-core classes).CamelCommandColorsTest: colored text without a terminal is printed without the ANSI codes.DependencyUpdateTestfailed once and passed on rerun; it fails once per run on every branch.Not in this PR
camel.shandcamel.batto choose it per command, because a foregroundcamel runruns the integration in the CLI JVM and must keep C2. It saves about 10-25 ms more per command. Like the AOT cache (CAMEL-26940, moved to 4.25), it is left out of this PR.Claude Code on behalf of davsclaus
🤖 Generated with Claude Code