commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: [logging] How do I change logging levels at run time?
Date Sun, 17 Aug 2003 02:14:24 GMT
On Mon, 11 Aug 2003, Henning P. Schmiedehausen wrote:

> Date: Mon, 11 Aug 2003 07:20:58 +0000 (UTC)
> From: Henning P. Schmiedehausen <hps@intermeta.de>
> Reply-To: Jakarta Commons Users List <commons-user@jakarta.apache.org>,
>      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" <craigmcc@apache.org> 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. ;-) :
>
>     /**
>      * <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 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 is<xxx>Enabled 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


Mime
View raw message