davsclaus opened a new pull request, #30016:
URL: https://github.com/apache/camel/pull/30016

   JIRA: [CAMEL-26937](https://issues.apache.org/jira/browse/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 
`SubstituteLogger`s 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](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to