Re: Fwd: Temporarily store/restore the current configuration
Chris Hostetter <[email protected]>
| Newsgroups | gmane.comp.jakarta.log4j.user |
|---|---|
| Message-ID | <alpine.DEB.2.21.2111081033320.3540@slate> |
: var ctx = (LoggerContext) LogManager.getContext(false);
: var current = ctx.getConfiguration();
: try {
: ctx.setConfiguration(myQuietConfiguration);
: otherCode();
: } finally {
: ctx.setConfiguration(current);
: }
:
: But it doesn't. Neither with reconfigure nor with setConfiguration.
: The root logger's appenders are never reattached properly.
:
: I wonder what I'm missing here. I've tried several other avenues but I
Dawid: The piece you're missing is LoggerContext.updateLoggers(...)
You can see examples of what you're describing in Solr's @LogLevel
and ErrorLogMuter ...
https://github.com/apache/solr/blob/main/solr/test-framework/src/java/org/apache/solr/util/LogLevel.java
https://github.com/apache/solr/blob/main/solr/test-framework/src/java/org/apache/solr/util/ErrorLogMuter.java
-Hoss