Temporarily store/restore the current configuration

Dawid Weiss <[email protected]>
Newsgroups gmane.comp.jakarta.log4j.user
Message-ID <CAM21Rt-ss+zLuA_Tk5KZKMAdo2cov_UDf3m6xef+mZ_kJmAxnQ@mail.gmail.com>
Hello,

I've been looking for a solution to a problem and I can't figure out
the solution. I have test code that recursively calls certain routines
which emit quite a bit of logging to the console. I'd like to
temporarily switch the configuration to one that is less chatty, but
restore the previous configuration afterward.

I looked at the LoggerContext and its reconfigure(Configuration) and
setConfiguration(Configuration) methods, thinking something like this
would work:

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 appender is never reattached properly.

I wonder what I'm missing here. I've tried several other avenues but I
will spare you the code as none of them worked properly. Any help
would be greatly appreciated.

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