I am using Log4j in my applications. log4j.properties
is placed in a Jar which is in classpath. This configuration file is being used and works fine most of the times.
But sometimes, the logging statements that are getting generated are not as per the configuration file.
My understanding is, this is because the properties file is fetched from the class path. Whatever first properties file is, is fetched and used by log4j. Thus sometimes we get the logging statements different from what is configured in properties file.
In case, the above reason is true, then I think, we need to specify the configuration file specifically by one of the following ways:
- Specify using System Properties : -Dlog4j.configuration=log4j.properties
- Initializing Log4jInit servlet.
Please suggest which could be the better approach.
In my application I am using
${user.home}
dir to storelog4j.properties
and using ant we are reading it. it will be platform independent. also you can pass one with build in classpath but reading from ${user.home} is better approach, You or any non technical person can easily access it.also you can use
Also See
When searching for items on the classpath the first instance of file with a matching name is used. So add your .jar to the front.