Example 15-7. A log4j configuration file using an XML format
You normally place this XML file in the WEB-INF/classes directory, just as with the log4j.properties file. However, you must set the log4j.configuration system property equal to the name of the file, so that the log4j environment knows which file to load. There’s no default filename when using the XML format. (We didn’t have to do this with the properties file because the name log4j.properties is part of the log4j default initialization. If it locates this file anywhere in the classpath, it will use it to initialize the log4j environment.) There are various ways to set the log4j.configuration property, and the various containers may provide alternative methods. In Tomcat Version 4.0, for example, you can set a variable called CATALINA_OPTS in the catalina.bat file to provide this information to the logging environment. For example: set CATALINA_OPTS=-Dlog4j.configuration=log4j.xml When you start up Tomcat, the log4j environment will then be able to locate the XML configuration file. Other containers may provide alternate methods for setting the value, but you can always set the value on the Java command line as a system property. You will probably need to modify the container’s startup script using this approach, however: java -Dlog4j.configuration=log4j.xml If the log4j environment is unable to find a valid configuration file, either properties-based or XML- based, you will see something similar to the following message when you first attempt to initialize the logging environment: log4j:WARN No appenders could be found for logger XXX. log4j:WARN Please initialize the log4j system properly.
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.
This entry was posted
on Sunday, November 25th, 2007 at 11:15 pm and is filed under Domain.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.