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

   Part of [CAMEL-26911](https://issues.apache.org/jira/browse/CAMEL-26911), 
item D3: a background run wrote its log twice.
   
   ## Problem
   
   An integration started with `camel run --background` (also `camel debug 
--background`, `camel restart`, and the TUI/AI launcher) logs to two places:
   
   - `~/.camel/<pid>.log`: the log4j file appender. `camel log`, the TUI and 
the AI tools read this file.
   - `~/.camel/<pid>-run.log`: its stdout/stderr, redirected by 
`BackgroundLog`. The log4j console appender writes every line here too.
   
   The two files were byte-identical (27 MB each after 6 minutes of a chatty 
route), with no size limit.
   
   `-run.log` still has a purpose: it also catches what never goes through 
log4j, such as errors before logging is set up, `System.out` and a JVM crash. 
`camel run --background` prints it when startup fails, and `camel restart` 
shows its tail.
   
   ## Fix
   
   - `log4j2-color.properties` and `log4j2-no-color.properties`: the console 
appender gets a `ThresholdFilter` whose level is 
`${env:CAMEL_CLI_CONSOLE_LOG_LEVEL:-ALL}`. By default everything is printed, as 
before.
   - `BackgroundLog.redirect` sets `CAMEL_CLI_CONSOLE_LOG_LEVEL=WARN` on the 
child process. `-run.log` then gets only WARN and ERROR, plus anything printed 
outside logging.
     - WARN and ERROR stay so the startup failure report, the TUI/AI failure 
cause and `camel restart` still show why the integration failed. `<pid>.log` is 
deleted when the JVM exits, so they can't read it.
     - An environment variable instead of an option: a child of another Camel 
version (`--camel-version`) ignores it and logs as before.
   - The `Log:` line is printed once the integration has started, and points to 
`<pid>.log` (new `BackgroundLog.logOf`). It falls back to `-run.log` when there 
is no log file: logging off, JSON logging, or a logging config of the user's 
own.
     - Same for `camel restart` and the "still starting" message.
     - With `--background-wait=false` it prints `-run.log` right away, as 
before.
   - A `-run.log` left behind after a crash is removed by `camel dirty 
--clean`, as before. It is now small.
   
   ## Docs
   
   - `camel-jbang-managing.adoc` (background run and restart).
   - `camel-jbang-debugging.adoc`.
   - The 4.24 upgrade-guide bullet about `-run.log` (4.24 is not released yet, 
so the existing entry is extended instead of adding a new section).
   
   ## Tests
   
   `BackgroundLogTest`:
   - A background process gets `CAMEL_CLI_CONSOLE_LOG_LEVEL=WARN`.
   - Both CLI log4j configurations load with a console `ThresholdFilter` at 
`ALL` when the variable is not set, so the foreground is unchanged.
   - `logOf` returns `<pid>.log` once it exists.
   
   `RunTest`, `RestartProcessTest`, `IntegrationLauncherTest` and 
`IntegrationLauncherConsoleTest` pass.
   
   ## End-to-end
   
   A patched launcher ran a route that logs every 10 ms, in the background for 
5 seconds:
   
   | | `<pid>.log` | `<pid>-run.log` | `Log:` |
   |---|---|---|---|
   | main | 42 KB | 42 KB (the same) | `-run.log` |
   | this PR | 44 KB | 322 bytes (one WARN) | `<pid>.log` |
   
   A route with an unknown component still fails at startup with exit 70, and 
the report shows the ERROR and its cause. It no longer shows the INFO startup 
banner.
   
   _Claude Code on behalf of Claus Ibsen (davsclaus)_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   
   https://claude.ai/code/session_012nJsFsjqqFiwroeHRWaKbS
   


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