LOG4J Learning Notes (2) _LOG4J Configuration sample &spring integration log4j

Source: Internet
Author: User
Tags log4j
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>
-->



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.