Re: [D] Help with migrating from log4j to log4j2 (we also use a slf4j -> log4j) [logging-log4j2]
ppkarwasz (via GitHub) <[email protected]>
| Newsgroups | gmane.comp.jakarta.log4j.devel |
|---|---|
| Message-ID | <ghd-D_kwDOAKJSSM4AhuMF-b2d9a6b1-5406-400a-8079-aba51030b811@gitbox.apache.org> |
GitHub user ppkarwasz added a comment to the discussion: Help with migrating from log4j to log4j2 (we also use a slf4j -> log4j)
> ```java
> ctx.addPropertyChangeListener(
> evt -> {
> if ("config".equals(evt.getPropertyName())) {
> synchronized (lock) {
> enableLogging();
> }
> }
> });
> ```
The `PropertyChangeListener` is called each time `updateLoggers()` is called, but your listener also calls `updateLoggers()`, so I would expect a stack overflow to happen here.
> For number 1 do you mean create a xml file for sshlog to define things? Wouldn't reconfigure just get rid of that, because we use log4j2.xml?
Yes, calling `LoggerContext.reconfigure()` is only able to load a single configuration at a time, but you can create a merged configuration programmatically:
```java
ConfigurationFactory configFactory = ConfigurationFactory.getInstance();
AbstractConfiguration commonConfig = (AbstractConfiguration)
configFactory.getConfiguration(ctx, null, URI.create("classpath:log4j2-common.xml"));
AbstractConfiguration sshConfig = (AbstractConfiguration)
configFactory.getConfiguration(ctxl, null, URI.create("classpath:log4j2-ssh.xml"));
ctx.reconfigure(new CompositeConfiguration(Arrays.asList(commonConfig, sshConfig)));
```
GitHub link: https://github.com/apache/logging-log4j2/discussions/3914#discussioncomment-14332898
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]