davido opened a new issue, #4328:
URL: https://github.com/apache/logging-log4j2/issues/4328

   ## Description
   
   A `CompositeConfiguration` never invokes its child configurations' 
`doConfigure()`.
   During `setup()` it calls each child's `setup()` (to build the child node 
tree) and merges
   the trees, then the composite runs its **own** inherited 
`AbstractConfiguration.doConfigure()`
   on the merged tree.
   
   As a result, any element a custom `Configuration` adds *programmatically* by 
overriding
   `doConfigure()` — the documented customization pattern from
   [Extending Log4j / Programmatic 
configuration](https://logging.apache.org/log4j/2.x/manual/customconfig.html) —
   is silently dropped when that configuration participates in a composite
   (`log4j2.configurationFile=a.xml,b.xml`), on **both** the initial build and 
every reconfiguration.
   
   ## Root cause
   
   - `CompositeConfiguration.setup()` → `staffChildConfiguration(child)` calls 
only `child.setup()`.
   - `CompositeConfiguration` does **not** override `doConfigure()`, so the 
child's `doConfigure()`
     override is never run; only the merged node tree is configured.
   
   ```java
   // CompositeConfiguration
   private void staffChildConfiguration(final AbstractConfiguration 
childConfiguration) {
       childConfiguration.setPluginManager(pluginManager);
       childConfiguration.setScriptManager(scriptManager);
       childConfiguration.setup();          // <-- setup only; doConfigure() is 
never called
   }
   ```
   
   ## Impact
   
   A custom `ConfigurationFactory` / `Configuration` that adds appenders or 
loggers
   programmatically works with a single configuration file but **loses those 
elements under a
   composite configuration**, with no warning or error. This surfaced in a real 
integration
   (Gerrit's Log4j2 backend), which currently has to reject composite configs 
outright to avoid
   silently losing its programmatic logs.
   
   ## Reproducer
   
   A minimal JUnit test using a custom `Configuration` whose contribution is 
asserted present
   under a composite; it fails before the fix and passes after. (Attached to 
the PR.)
   
   ## Proposed fix
   
   Add a no-op `Configuration#postConfigure(Configuration target)` hook that
   `CompositeConfiguration.doConfigure()` invokes on each child **after** 
configuring the merged
   tree, so a custom configuration can re-apply its programmatic elements to 
the effective
   (composite) configuration. Because `reconfigure()` rebuilds a 
`CompositeConfiguration`, the
   hook also runs on every reconfiguration.
   
   A PR implementing this follows.
   
   ## Affected versions
   
   Observed on `2.26.x`; `2.25.1` is affected as well.
   


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