Skip to content

CAMEL-26937: camel-jbang - the short commands start without log4j, and print without a JLine terminal when piped - #30016

Merged
davsclaus merged 2 commits into
mainfrom
CAMEL-26937-cli-startup
Nov 15, 2026
Merged

davsclaus merged 2 commits into
mainfrom
CAMEL-26937-cli-startup

Conversation

@davsclaus

Copy link
Copy Markdown
Contributor

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 (FileUtil for camel 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 of RuntimeUtil also 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 the slf4j.provider system property, unless one is already set. Its loggers are slf4j SubstituteLoggers 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 call execute and keep the normal log4j binding.

No JLine terminal when the output is piped. printColored asked AnsiConsole to 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.mode is set. Output in a terminal is unchanged.

Measured

Launcher built from main today, JDK 25, warm CDS, best of 7, scratch home:

command main this PR
camel ps 237 ms 140 ms
camel get route 259 ms 170 ms
camel doc timer 245 ms 150 ms
camel log <name> --follow=false (piped) 439 ms 347 ms

Classes loaded by camel ps go from 3,383 to 1,764, with no log4j or Jackson 2 classes. camel run --logging-level=debug prints the same 556 lines as main, apart from hash codes and timings. A foreground run, a background run (log file, camel log), and --logging-category all 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 timer through 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.
  • Module suites: camel-jbang-run, camel-jbang-core and camel-launcher are green. DependencyUpdateTest failed once and passed on rerun; it fails once per run on every branch.

Not in this PR

  • Item 3 (C1 for the CLI JVM) needs camel.sh and camel.bat to choose it per command, because a foreground camel run runs 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.
  • Item 4 (the aesh registry scan that opens all jars) needs a change in aesh.
  • Seen while measuring: when the jars of an install change in place (same directory, same version), the JVM keeps the stale CDS archive. Classes are then no longer shared and the command is slower, and the archive is not recreated.

Claude Code on behalf of davsclaus

🤖 Generated with Claude Code

…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>
@davsclaus davsclaus added this to the 4.24.0 milestone Nov 15, 2026
@davsclaus davsclaus added dsl enhancement New feature or request labels Nov 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

🧪 CI tested the following changed modules:

  • dsl/camel-jbang/camel-jbang-core
  • dsl/camel-jbang/camel-jbang-run
  • dsl/camel-jbang/camel-launcher

🔬 Scalpel shadow comparison — Scalpel: 6 of 726 tested, 7 compile-only — current: 6 all tested

Maveniverse 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)
  • camel-jbang-mcp ← downstream of org.apache.camel:camel-jbang-core
  • camel-jbang-plugin-mcp ← downstream of org.apache.camel:camel-jbang-core
  • camel-jbang-plugin-tui ← downstream of org.apache.camel:camel-jbang-core
  • camel-jbang-plugin-validate ← downstream of org.apache.camel:camel-jbang-core
  • camel-jbang-run ← dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/common/CliLoggerProvider.java, dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/common/CliLogging.java, dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/common/RuntimeUtil.java, dsl/camel-jbang/camel-jbang-run/src/test/java/org/apache/camel/dsl/jbang/run/common/CliLoggerProviderTest.java, dsl/camel-jbang/camel-jbang-run/src/test/java/org/apache/camel/dsl/jbang/run/common/CliLoggingTest.java
  • camel-launcher-container ← downstream of org.apache.camel:camel-launcher
Modules with tests skipped (7)
  • camel-jbang-it
  • camel-jbang-main
  • camel-jbang-plugin-edit
  • camel-jbang-plugin-generate
  • camel-jbang-plugin-kubernetes
  • camel-jbang-plugin-test
  • coverage

ℹ️ Shadow mode — Scalpel observes but does not affect test execution. Learn more

⚠️ Some tests are disabled on GitHub Actions (@DisabledIfSystemProperty(named = "ci.env.name")) and require manual verification:

  • dsl/camel-jbang/camel-jbang-core: 2 test(s) disabled on GitHub Actions

💡 Manual integration tests recommended:

You modified dsl/camel-jbang/camel-jbang-core, dsl/camel-jbang/camel-launcher. The related integration tests in dsl/camel-jbang/camel-jbang-it are excluded from CI. Consider running them manually:

mvn verify -f dsl/camel-jbang/camel-jbang-it -Djbang-it-test
All tested modules (15 modules, 3m 19s total)

Total reactor time: 3m 19s

Module Duration Status
Camel :: JBang :: Plugin :: TUI 53.0s SUCCESS
Camel :: JBang :: MCP 49.7s SUCCESS
Camel :: JBang :: Plugin :: Validate 23.6s SUCCESS
Camel :: JBang :: Run 23.2s SUCCESS
Camel :: JBang :: Plugin :: Kubernetes 15.8s SUCCESS
Camel :: JBang :: Plugin :: Testing 14.0s SUCCESS
Camel :: JBang :: Plugin :: Generate 7.9s SUCCESS
Camel :: Coverage 5.2s SUCCESS
Camel :: JBang :: Plugin :: Edit 1.9s SUCCESS
Camel :: JBang :: Plugin :: MCP 1.8s SUCCESS
Camel :: JBang :: Integration tests 1.3s SUCCESS
Camel :: JBang :: Main 1.2s SUCCESS
Camel :: Launcher :: Container 0.7s SUCCESS
Camel :: JBang :: Core n/a
Camel :: Launcher n/a

Top 20 slowest modules:

  • Camel :: JBang :: Plugin :: TUI (53.0s)
  • Camel :: JBang :: MCP (49.7s)
  • Camel :: JBang :: Plugin :: Validate (23.6s)
  • Camel :: JBang :: Run (23.2s)
  • Camel :: JBang :: Plugin :: Kubernetes (15.8s)
  • Camel :: JBang :: Plugin :: Testing (14.0s)
  • Camel :: JBang :: Plugin :: Generate (7.9s)
  • Camel :: Coverage (5.2s)
  • Camel :: JBang :: Plugin :: Edit (1.9s)
  • Camel :: JBang :: Plugin :: MCP (1.8s)
  • Camel :: JBang :: Integration tests (1.3s)
  • Camel :: JBang :: Main (1.2s)
  • Camel :: Launcher :: Container (0.7s)

⚙️ View full build and test results

…er sentences (review)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
@davsclaus davsclaus self-assigned this Nov 15, 2026
@davsclaus
davsclaus merged commit ce22a13 into main Nov 15, 2026
13 checks passed
@davsclaus
davsclaus deleted the CAMEL-26937-cli-startup branch November 15, 2026 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dsl enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants