Return-Path: Delivered-To: apmail-jakarta-commons-user-archive@www.apache.org Received: (qmail 40047 invoked from network); 12 Jun 2007 04:07:30 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 12 Jun 2007 04:07:30 -0000 Received: (qmail 50603 invoked by uid 500); 12 Jun 2007 04:07:28 -0000 Delivered-To: apmail-jakarta-commons-user-archive@jakarta.apache.org Received: (qmail 50549 invoked by uid 500); 12 Jun 2007 04:07:27 -0000 Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Users List" Reply-To: "Jakarta Commons Users List" Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 88161 invoked by uid 99); 11 Jun 2007 20:23:37 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: local policy) Subject: Re: turn off common logging From: simon To: Jakarta Commons Users List In-Reply-To: <7fc8f9070706111216h3974e10di93b5e4d454138817@mail.gmail.com> References: <910173.81942.qm@web60723.mail.yahoo.com> <7fc8f9070706111216h3974e10di93b5e4d454138817@mail.gmail.com> Content-Type: text/plain Date: Mon, 11 Jun 2007 21:56:33 +0200 Message-Id: <1181591793.5983.19.camel@simon-laptop> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Yep, I agree with Rodrigo's comment. However there are a number of other things to consider. (1) Which logging library is used at runtime depends on what libraries are in the classpath. If log4j is in the classpath, then it will be used by default. If jdk1.4 or later is used, then the jdk14 logging will be used. If neither of these are true then SimpleLog will be used. Presumably you know what the classpath and JVM are for your application, so you know which logging library will be used. Use the appropriate configuration setting for that library - ie log4j config environment vars or config files if log4j is present, or JCL config settings, or SimpleLog settings as appropriate. As Rodrigo noted, you can force selection of a certain lib via environment vars; I've never needed this though - just fix the classpath. (2) Using code to set logging levels is generally not a good idea; it removes control from the user of your application. What if the person using your code wants different values? Generally, therefore, it's best to use environment variables to control logging rather than hard-coding settings. (3) If you really don't want any logging then you can just force org.apache.commons.logging.impl.NoOpLog to be used as the implementation. In this case, all logging is discarded automatically and no level needs to be set. (4) Rodrigo suggested using an environment var to force a certain log library to be used. If you are tempted to set this in your code rather than via an environment variable (which I don't recommend BTW) then you probably need to do it in a static code block in your main class rather than within the main method, eg package foo.bar; class MyMainClass { static { System.setProperty(....); } } The org.apache.commons.logging.Log environment variable is used only once - when the first Log object is created. After that it is ignored. Regards, Simon On Mon, 2007-06-11 at 16:16 -0300, Rodrigo Canabrava wrote: > Hello, > > The property you set works if you are using the SimpleLog > implementation. If it didn't work, then you're using another one. > Pay attention to the fact that, by default, SimpleLog will be the last > option that commons logging will try to use. If you're using JDK 1.4 > or later, then commons-logging will choose the Jdk14Logger. > > You can try to force the use of SimpleLog, including the system property: > > org.apache.commons.logging.Log = org.apache.commons.logging.impl.SimpleLog > > (it also works including the previous line in the > commons-logging.properties file) > > After that, setting the level to fatal the way you did should work. > > a+ > Rodrigo > > > 2007/6/11, Cheok Yan Cheng : > > Hello, > > > > This is the first time I am using common logging > > library. > > > > May I know how I can turn-off all the logging message > > in my application? I search the documentation, I try > > to set the logging level to fatal (all my log are in > > info and error). However, I still see my log message > > print out. Please advice. Thanks. > > > > I try to turn off it through the following code. Is it > > correct? > > > > Thanks! > > > > > > private static final Log log = > > LogFactory.getLog(MainFrame.class); > > > > /** > > * @param args the command line arguments > > */ > > public static void main(String args[]) { > > > > System.setProperty("org.apache.commons.logging.simplelog.defaultlog", > > "fatal"); > > > > > > > > > > > > > > > > ____________________________________________________________________________________ > > Don't get soaked. Take a quick peak at the forecast > > with the Yahoo! Search weather shortcut. > > http://tools.search.yahoo.com/shortcuts/#loc_weather > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org > > For additional commands, e-mail: commons-user-help@jakarta.apache.org > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org > For additional commands, e-mail: commons-user-help@jakarta.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-user-help@jakarta.apache.org