Fwd: Temporarily store/restore the current configuration

Dawid Weiss <[email protected]>
Newsgroups gmane.comp.jakarta.log4j.user
Message-ID <CAM21Rt-mQD6_cvkp2v8otS5otqtgO8=abUmPL-j4Ta0NzCg0CQ@mail.gmail.com>
Hello,

I've been looking at a seemingly simple problem I can't figure out the
solution for - hope it's something you've encountered before.

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 logging configuration to one that is less chatty, but
restore the previous configuration afterward (as if nothing changed). Everything
is single-threaded.

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 appenders are 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 or pointers
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.