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 8806 invoked from network); 11 Aug 2003 07:20:53 -0000 Received: from mail.hometree.net (212.34.181.120) by daedalus.apache.org with SMTP; 11 Aug 2003 07:20:53 -0000 Received: from tangens.hometree.net (IDENT:news@mail.hometree.net [212.34.181.120]) by mail.hometree.net (8.12.9/8.12.9) with ESMTP id h7B7KwVA002035 for ; Mon, 11 Aug 2003 09:20:58 +0200 Received: (from news@localhost) by tangens.hometree.net (8.12.9/8.12.8/Submit) id h7B7KwQr002034 for commons-user@jakarta.apache.org; Mon, 11 Aug 2003 09:20:58 +0200 To: commons-user@jakarta.apache.org Path: not-for-mail From: "Henning P. Schmiedehausen" Newsgroups: hometree.jakarta.commons.user Subject: Re: [logging] How do I change logging levels at run time? Date: Mon, 11 Aug 2003 07:20:58 +0000 (UTC) Organization: INTERMETA - Gesellschaft fuer Mehrwertdienste mbH Lines: 75 Message-ID: References: <20030810182631.Q48452@minotaur.apache.org> Reply-To: hps@intermeta.de NNTP-Posting-Host: forge.intermeta.de X-Trace: tangens.hometree.net 1060586458 1444 212.34.181.4 (11 Aug 2003 07:20:58 GMT) X-Complaints-To: news@intermeta.de NNTP-Posting-Date: Mon, 11 Aug 2003 07:20:58 +0000 (UTC) X-Copyright: (C) 1996-2003 Henning Schmiedehausen User-Agent: nn/6.6.5 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N "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? Regards Henning -- Dipl.-Inf. (Univ.) Henning P. Schmiedehausen INTERMETA GmbH hps@intermeta.de +49 9131 50 654 0 http://www.intermeta.de/ 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 <3F1874B0.6030507@coyotegulch.com>