Re: Dynamic Update of Log Priority

"Simone Bordet" <[email protected]>
Newsgroups gmane.comp.java.mx4j.user
Message-ID <[email protected]>
Hi Jens,

On 9/4/07, Rottgardt, Jens (K-SOB-2/3) <[email protected]> wrote:
> Hi,
>
> I want to change the mx4j logging priority during run time. This does not
> work. It seems that the logging priority of an existing logger is not
> updated when calling Log.setDefaultPriority(priority) ?!

You can change the priority directly on the logger instance if you
have access to it.

A slightly more complicated solution would be to:
1. Call Log.redirectTo(null); this will clear the cache of Loggers
(see below why this matters)
2. Call Log.setDefaultPriority(newPriority);
3. Avoid to use in your code the pattern of registering the Logger
instance as instance or static variable, as this prevents changing the
priority dynamically, but always use Log.getLogger(), that will check
in the cache, find nothing, and recreate the logger, this time with
the new priority.

Basically you have to change this:

class Foo
{
   private Logger logger = Log.getLogger("bar");

   public void method()
   {
      logger.debug("baz");
   }
}

into this:

class Foo
{
   public void method()
   {
      Log.getLogger("bar").debug("baz");
   }
}

In conjunction with 1 and 2 above, should allow you to change the
priority dynamically, paying a bit in performance (a cache lookup by
getLogger() every time).
Let us know if it worked.

Simon
--
http://bordet.blogspot.com

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
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.