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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.