Return-Path: Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 44451 invoked from network); 17 Aug 2003 02:14:07 -0000 Received: from unknown (HELO minotaur.apache.org) (209.237.227.194) by daedalus.apache.org with SMTP; 17 Aug 2003 02:14:07 -0000 Received: (qmail 94304 invoked by uid 1059); 17 Aug 2003 02:14:24 -0000 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 17 Aug 2003 02:14:24 -0000 Date: Sat, 16 Aug 2003 19:14:24 -0700 (PDT) From: "Craig R. McClanahan" To: Jakarta Commons Users List , hps@intermeta.de Subject: Re: [logging] How do I change logging levels at run time? In-Reply-To: Message-ID: <20030816191132.C88673@minotaur.apache.org> References: <20030810182631.Q48452@minotaur.apache.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam-Rating: localhost 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N On Mon, 11 Aug 2003, Henning P. Schmiedehausen wrote: > Date: Mon, 11 Aug 2003 07:20:58 +0000 (UTC) > From: Henning P. Schmiedehausen > Reply-To: Jakarta Commons Users List , > hps@intermeta.de > To: commons-user@jakarta.apache.org > Newsgroups: hometree.jakarta.commons.user > Subject: Re: [logging] How do I change logging levels at run time? > > "Craig R. McClanahan" writes: > > >On Mon, 11 Aug 2003 dion@multitask.com.au wrote: > > >> Is this possible with commons-logging, or must we use log4j to do this? > > >You'll need to use your underlying logging system's configuration > >mechanism for stuff like this. > > Hi Dion, Craig, > > I was thinking about this when I read about it on the maven-dev list > and this is a suggestion how to solve it (I don't know much about the > innard of commons-logging, I'm just a happy user): > > The problem is, that the log level is hard coded into the method names. > You have "log.error, log.debug, log.notice" on the Log interface. > > So let's extend it with a new level called "default" (if you know any > better name, good. I wasn't able to invent a better one. ;-) : > > /** > *

Is default logging currently enabled?

> * > *

Call this method to prevent having to perform expensive operations > * (for example, String concatination) > * when the log level is more than the default level.

> */ > public boolean isDefaultEnabled(); > > /** > *

Log a message with default log level.

> * > * @param message log this message > */ > public void default (Object message); > > Which would use a "default" log level set by a System.property or any > other means. This would allow an application to log its stuff at debug > level when developing and at application level when running. > > In the Log4JLogger this would be quite a simple implementation: > > public void default (Object message) { > logger.log(FQCN, currentPrio, message, null); > } > > with isDefaultEnabled a little more heavy because one would have to > look which isEnabled method on the logger is to be used. This > would need a little reflection or a simple switch(currentPrio) > statement. > > Getting the currentPrio setting in the C'tor of Log4JLogger from a > System.property shouldn't be a problem. > > I'd like to see this, it would add flexibility to the commons-logging > system while keeping the implementation independence that I like from > it. > > Comments? > One very large issue is that Log is an interface, so that adding a new method like this would break every existing Log implementation in the world. That's not a good thing to do to users. As an alternative, you can certainly create your own Log implementation that simply delegates calls to the standard c-l version, but adds the extra method signatures. > Regards > Henning > > > > Craig