http://yzxqml.iteye.com/blog/1761540
————————————————————————————————————————————————————————————————————————————————
LOG4J is an Apache open source project, through the use of log4j, we can control the log information delivery destination is the console, files, GUI components, even the socket server, NT Event recorder, UNIX syslog daemon, etc. We can also control the output format of each log, and by defining the level of each log information, we can control the log generation process more carefully. Most interesting of all, these can be configured flexibly with a single configuration file, without the need to modify the code of the application.
In fact, I think he is a component that can monitor our web application, so that we can see how our program is running and the related records after the error.
I reported a mistake when I was using it.
Class for the ' Webapprootkey ' Context-param in your web. XML files!
Let's take a look at the configuration of log4j:
Log4j.rootlogger=INFO, stdout, Logfilelog4j.appender.stdout=Org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.layout=Org.apache.log4j.htmllayout#log4j.appender.stdout.layout.conversionpattern=%d%p [%c]-%m%Nlog4j.appender.stdout.layout.ConversionPattern=-%m%Nlog4j.appender.logfile=Org.apache.log4j.RollingFileAppender Log4j.appender.logfile.File=${webapp.root}/webapp.htmllog4j.appender.logfile.MaxFileSize=512kb# Keep three backup Files.log4j.appender.logfile.MaxBackupIndex=3# Pattern to output:date Priority [Category]-Messagelog4j.appender.logfile.layout=Org.apache.log4j.HTMLLayoutlog4j.appender.logfile.layout.ConversionPattern=%d%p [%c]-%m%NLOG4J.LOGGER.COM.OPENSYMPHONY.XWORK2=ERROR # Control Logging forOther open source Packageslog4j.logger.org.springframework=ERRORlog4j.logger.org.quartz=ERRORlog4j.logger.net.sf.ehcache=ERRORlog4j.logger.net.sf.navigator=ERRORlog4j.logger.org.apache.commons=ERRORlog4j.logger.org.apache.struts=ERRORlog4j.logger.org.hibernate=DEBUG # Struts ognlutil issues unimportant warnings Log4j.logger.com.opensymphony.xwork2.util.OgnlUtil=Error Log4j.logger.com.opensymphony.xwork2.ognl.OgnlValueStack=error
Found that there is no problem ah, but, please note ${webapp.root} This variable, with the error hint about a glance, meaning that the Web application root system properties have been set, it is said that the "Webapp.root" This configuration name has been used, no longer use this ,
It also prompts choose unique values for the ' Webapprootkey ' Context-param in your. xml files, which means that we can configure a unique ' Webappro ' in Web. xml Otkey ', so there will be no conflict.
This problem can occur when a Web server deploys multiple applications that use LOG4J, and if configured improperly, this error can really make you depressed and crazy. That's the problem. A Tomcat deploys 2 projects that use log4j.
Then I fix it: press the hint in Web. XML to add
<context-param> <param-name>webAppRootKey</param-name> <param-value>myapp.root </param-value></context-param>
Then write ${myapp.root} in the Log4j.properties, as long as the name is not duplicated, it will not produce the Web App root system property already set to different value error. While it is relatively rare to deploy multiple applications on a single server when it is used formally, it is still safe to use, but also to standardize our program-related nomenclature,
${webapp.root} is a good habit to change to ${[application].root}.