commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <si...@ecnetwork.co.nz>
Subject Re: configuring Logging
Date Wed, 02 Jun 2004 23:06:51 GMT
Hi Ashish,

On Thu, 2004-06-03 at 03:47, Ashish Naik wrote:
> I am not able to understand how to confifigure Log4J for Commons logging
> API.
> 
> I have added log4j.jar to my classpath. How do I set
> log4j.configuration=log4j.properties
> 
> I am refering to Logging User Guide at
> http://jakarta.apache.org/commons/logging/guide.html

Unfortunately, some of the other replies to your question are not quite
correct, or more complex than is needed.

Firstly, to use log4j as the "back end" for an application that uses
commons-logging, you normally just:
a) put log4j.jar in the classpath, and
b) put a file named "log4j.xml" or "log4j.properties" in the classpath.

On startup, commons-logging detects that the log4j libraries are
present, and initialises log4j. Log4j then searches for its config files
in the classpath. Note that it is not *commons-logging* that configures
log4j. All commons-logging does is find and invoke the log4j
initialisation method; the rest is done by log4j.


The commons-logging documentation page you refer to above talks about
"system properties". These are values that application code can retrieve
using the API call:
  String value = System.getProperty("who");
These are set by running java like this:  
  java -Dwho=me  ......

So what the page referred to is saying is that if your log4j.properties
file is not in the classpath, or is not named "log4j.properties"  then
you can still tell log4j where to find it by running your application
as:
  java -Dlog4j.configuration=/var/myconfigfile.props .....

As a side-note, I *much* prefer to use xml-format log4j configuration
files. They are easier to read, and have features not available when
using the properties format configuration files.



Re Fredrick's email, which states that a commons-logging configuration
file is necessary. He is correct that such a file *can* be used. But
normally it is not necessary. If you have more than one logging library
in your classpath and you don't like the one that commons-logging
selects by default, you could use this to force your preferred lib to be
used. And you can use this to configure your own custom logging
implementation (which is not at all common). Otherwise, it is not
needed.

Re Shrihas's email: this code is technically correct. But it means that
the application is now directly linked to the log4j libraries, which
rather spoils the goal of commons-logging. This solution (and the one
described out by Florian) can be appropriate in some situations where
you want to force log4j to retrieve configuration from some non-standard
place. But in general it is not necessary. And by the way, this is a
log4j-specific technique, and is not related to commons-logging.

For most users, just placing log4j.jar and log4j.xml (or
log4j.properties) in the classpath is all that is needed.



I hope this helps,


Simon


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message