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

   [CAMEL-25820](https://issues.apache.org/jira/browse/CAMEL-25820): the 
logging configuration of camel-jbang-core left log files in `~/.camel`. One 
machine had 17 of them, from Oct 15 to Oct 19, from three sources:
   
   1. **A file named `${sys:pid}.log`.** `log4j2.properties` was the 
configuration of `camel run` (with color) and also the one log4j finds on the 
classpath of any JVM with camel-jbang-core. Its file is named after the `pid` 
system property, which only the CLI sets. A JVM that uses camel-jbang-core 
without the CLI, such as a test of a module that depends on it, wrote its first 
log line to `~/.camel/${sys:pid}.log`.
   2. **`<pid>.log` of `camel test run`.** The command sets `pid`, log4j then 
loads the same configuration, and only `camel run` removes its log. 9 files.
   3. **`<pid>.log` of tests that run Camel.** The configurations name the file 
after `user.home`, while the CLI keeps its files in its own Camel directory 
(`CommandLineHelper.getCamelDir()`). A test with a home of its own logged into 
the real `~/.camel`, and the run looked for its log in its own home. 7 files of 
about 450 KB, from the tests of camel-jbang-plugin-kubernetes.
   
   The same split also affects a user without a home, such as in a container: 
Java sets `user.home` to `?`, and the CLI then uses `$HOME`, but log4j wrote 
under `?`.
   
   ## What
   
   - **`log4j2.properties` logs to the console only.** It is now only the 
configuration log4j finds on the classpath when nothing configures logging. The 
configuration of `camel run` with color is `log4j2-color.properties`, next to 
`log4j2-no-color.properties`. `RuntimeUtil` loads it by name, in the two places 
that loaded `log4j2.properties`.
   - **The log files go to the Camel directory of the CLI.** `RuntimeUtil` sets 
the system property `camel.jbang.logDir` to `CommandLineHelper.getCamelDir()` 
before it loads a configuration. The five configurations with a file 
(`<pid>.log`, `camel-export.log`, `camel-script.log`) use it, with `~/.camel` 
under `user.home` as the fallback when it is not set. So log4j writes where 
`camel run`, `camel log` and the AI tools look.
   - **A Quarkus app that `camel run` exports and runs** logs to the same 
directory. Its `application.properties` had `${user.home}/.camel/<name>.log`, 
while an existing Quarkus project already used the Camel directory of the CLI.
   
   The colored console of the classpath configuration stays as it was.
   
   ## Tests
   
   - New `LogConfigurationTest` (7). It loads each configuration into a logger 
context of its own, so the logging of the tests is not changed, and checks the 
name of the log file as log4j resolves it:
     - in the directory that `camel.jbang.logDir` names, for the five 
configurations with a file;
     - in `~/.camel` without it (log4j resolves a lookup nested in the default 
value);
     - `log4j2.properties` has console appenders only.
   - End to end, with the camel launcher built from this branch:
     - `camel run` with `user.home=?` and `HOME` set. Before: the CLI made an 
empty `<home>/.camel/60831.log`, and log4j wrote the 13 lines to 
`./?/.camel/60831.log` in the working directory. After: the 13 lines are in 
`<home>/.camel/60872.log`, and there is no `?` directory.
     - A test in camel-jbang-plugin-validate that logs one warning with SLF4J 
(run with its own `user.home`). Before: it wrote `~/.camel/${sys:pid}.log`. 
After: the warning is on the console only, and no file is written.
   - All tests of camel-jbang-core pass (2312, 2 skipped, and 237).
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   
   https://claude.ai/code/session_01STT6whBgK1AqsSsUKrnE8m
   


-- 
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