Log4j.properties Read Webapp.root value failed, resulting in setfile (null,..) Solutions for

Source: Internet
Author: User

This problem has afflicted me for a whole day, and I hereby write to help the little friends of the future to make less detours.

I'll describe the environment first, and you'll see if it's similar to your situation.

Spring and log4j are used in the project, Org.springframework.web.util.Log4jConfigListener monitoring is used, ${webapp.root is configured in Log4j.properties} To get the Webapprootkey configured in Web. Xml. The approximate relevant code is as follows:


Xml:

<context-param>  <param-name>webAppRootKey</param-name> <param-value>szweb.root</ param-value></context-param> <context-param>  <param-name>log4jconfiglocation</ Param-name>  <param-value>/web-inf/classes/log4j.properties</param-value></context-param >  <context-param>  <param-name>log4jRefreshInterval</param-name>  < Param-value>60000</param-value></context-param> <listener> <listener-class> Org.springframework.web.util.log4jconfiglistener</listener-class></listener>  

Log4j.properties:


Log4j.appender.logfile_error. File=${webapp.root}/web-inf/logs/systemerror.log


Online streaming results in setfile (null,..) The reason is
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
Need to be set into classpath:log4j.properties


And in my project, the reason I found out is:

The order of execution of the listener results in ...


The order of execution in Web. XML is such a context-param-->listener-->filter-->servlet, and listener is executed in the order you write ...

My project exists ab two Listener,alistener in front, which has done some system business parameters initialization, Blistener is Log4jconfiglistener, originally is no problem, but a in the operation of the log, So in the Blistener has not yet come into force before the request log4j began to do log processing, so log4j classmate went to find their own configuration file, and then found that there is a ${webapp.root}, and then it went to the property inside the system to find, Found no and then an error ... Why not? Because Blistener actually reads the Servlet.realpath, and then associates the Webapprootkey you set with the Realpath, and saves it to the system's property ... As a result B had not had time to dry, a went to find ...


I found the reason ... (Before Google ... The degree Niang all asked ... No one, like me, eventually looked at what the Log4jconfiglistener had done, and then remembered that it might have been the order of execution .


All right, the end of the scatter flower

Log4j.properties Read Webapp.root value failed, resulting in setfile (null,..) Solutions for

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.