commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henning P. Schmiedehausen" <>
Subject Re: [logging] How do I change logging levels at run time?
Date Mon, 11 Aug 2003 07:20:58 GMT
"Craig R. McClanahan" <> writes:

>On Mon, 11 Aug 2003 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. ;-) :

     * <p> Is default logging currently enabled? </p>
     * <p> Call this method to prevent having to perform expensive operations
     * (for example, <code>String</code> concatination)
     * when the log level is more than the default level. </p>
    public boolean isDefaultEnabled();

    * <p> Log a message with default log level. </p>
    * @param message log this message
   public void default (Object message);

Which would use a "default" log level set by a 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 is<xxx>Enabled method on the logger is to be used. This
would need a little reflection or a simple switch(currentPrio)

Getting the currentPrio setting in the C'tor of Log4JLogger from a 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



Dipl.-Inf. (Univ.) Henning P. Schmiedehausen          INTERMETA GmbH        +49 9131 50 654 0

Java, perl, Solaris, Linux, xSP Consulting, Web Services 
freelance consultant -- Jakarta Turbine Development  -- hero for hire

"You are being far too rational for this discussion."  
       --- Scott Robert Ladd in <>

View raw message