LOG4J configuration considerations in Web. xml

Source: Internet
Author: User
Tags tomcat log4j

Web. XML Webapprootkey

1. Web. XML Configuration
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>webapp.root</param-value>
</context-param>
The string "Webapp.root" can be arbitrarily written in any string. If you do not configure the default value is "Webapp.root".

You can use System.getproperty ("Webapp.root") to dynamically get the project's running path.
General return results For example:/usr/local/tomcat6/webapps/project name

2. Resolve the following error

Web projects deployed in the same container, to be configured with different <param-value>, cannot be duplicated, otherwise the report resembles the following error:
Web App root system property already set to different value: ' Webapp.root ' = [/home/user/tomcat/webapps/project1/] instead of [/home/user/tomcat/webapps/project2/]-Choose unique values for the ' Webapprootkey ' Context-param in your web. XML fil Es!
This means that the "webapp.root" key already points to item 1 and cannot point to item 2.

3. Loading mode

Spring works by Org.springframework.web.util.WebAppRootListener the listener to run the project path.
However, if the Org.springframework.web.util.Log4jConfigListener listener is already configured in Web. XML,
You do not need to configure the Webapprootlistener. Because Log4jconfiglistener already contains the functions of Webapprootlistener.
General configuration Type the following example: XML code <!--load log4j configuration file--<context-param> <param-name>log4jconfiglocation</         Param-name> <param-value>WEB-INF/conf/log4j.properties</param-value> </context-param> <context-param> <param-name>log4jRefreshInterval</param-name> <param-value>3000< /param-value> </context-param> <listener> <listener-class>org.springframework.web.util. Log4jconfiglistener</listener-class> </listener>

<!--configured with a listener, you can also configure Servlet:-->  
<!--   
<servlet>  
 <servlet-name>log4j</ servlet-name>  
 <servlet-class>  
 org.springframework.web.util.Log4jConfigServlet  
 </ servlet-class>  
 <load-on-startup>1</load-on-startup>  
 </servlet>  


log4jrefreshinterval in Web. XML

Log4jrefreshinterval is 3000 to open a watchdog thread to scan for changes in configuration files every 3 seconds.

The ability to dynamically modify the Log4j.properties key, the container scans the log4j configuration file every 3 seconds.


4. Dynamically identify the path to the project at run time

In the log4j.properties configuration file, you can use ${webapp.root} as follows:
Log4j.appender.file.file=${webapp.root}/web-inf/logs/sample.log
You can dynamically find the path to the project at run time

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.