log4j Configuration Sample
#定义根日志级别和输出端 (two outputs defined) Log4j.rootlogger=error,console,orclight #定义第一个输出端, output to console log4j.appender.console=
Org.apache.log4j.ConsoleAppender Log4j.appender.console.layout=org.apache.log4j.patternlayout log4j.appender.console.layout.conversionpattern=%d [%t]%-5p%c (%l)-%m%n #定时第二个输出端, output to a file with a maximum space of 1000KB, Automatically back up after 1000KB, generate new files Log4j.appender.orclight=org.apache.log4j.rollingfileappender log4j.appender.orclight.file=
Orclight.log Log4j.appender.orclight.layout=org.apache.log4j.patternlayout log4j.appender.orclight.layout.conversionpattern=%d [%t]%-5p%c (%l)-%m%n log4j.appender.orclight.maxfilesize= 1000KB log4j.appender.orclight.maxbackupindex=10 #定义具体某个包下的日志输出级别 Log4j.logger.com.orclight.rbac=info,orclight,
CONSOLE Log4j.logger.com.orclight.rbac.services.impl.cacheserviceimpl=info,orclight
Log4j.logger.org.springframework=error,orclight Log4j.logger.org.springframework.jdbc.support=info
Log4j.logger.org.springframework.scheduling=info #定义sql语句的输出级别 Log4j.logger.java.sql.connection=debug
# Struts Ognlutil issues unimportant warnings log4j.logger.com.opensymphony.xwork2.util.ognlutil=error
Log4j.logger.com.opensymphony.xwork2.ognl.ognlvaluestack=error
integrating log4j in spring
Configure log4j for spring in a Web application
The practice of spring is to use a servlet Listener to write the absolute path of root to the system variable when the Web container is started, so that the log4j configuration file can be ${myappfuse.root} To represent the system variables that have just been set up: Log4j.appender.logfile.file=${myappfuse.root}/logs/mylog.log
The configuration statements in Web.xml are as follows:
<context-param>
<param-name>webAppRootKey</param-name>
<param-value> myappfuse.root</param-value>
</context-param>
<context-param>
<param-name> Log4jconfiglocation</param-name>
<param-value>/web-inf/classes/log4j.properties</ param-value>
</context-param>
<listener>
<listener-class> org.springframework.web.util.log4jconfiglistener</listener-class>
</listener>
<!-- A listener is configured here, and servlet:-->
<!--
<servlet>
<servlet-name>log4j</can also be configured servlet-name>
<servlet-class>
org.springframework.web.util.Log4jConfigServlet
</ servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
-->