SSH Framework Configuration log4j

Source: Internet
Author: User

1. log4j (log4j.properties) configuration file

Define the log configuration file and place it in the Web-info directory.

LOG4J.LOGGER.OPERATELOG=INFO,A1
# # #输出到日志文件 ###
log4j.appender.a1= Org.apache.log4j.DailyRollingFileAppender
log4j.appender.a1.file=e:\\file.log
log4j.appender.A1.layout =org.apache.log4j.patternlayout
log4j.appender.a1.layout.conversionpattern=%-d{yyyy-mm-dd HH\:mm\:ss} [%t\:% R]-[%P]%m%n
Where the Operatelog is the name of the custom log, used when invoked, which can define multiple different log output configurations, which are invoked when invoked.

Info is the log output level, mainly: ERROR, WARN, INFO, DEBUG

Error is a critical error, mostly a program bug.
WARN as a general warning, such as session loss
Info for general information to be displayed, such as login logout
Debug is debugging information for the program

A1 is the destination of the output, can be multiple, directly following, separated by commas. Represents the output of log level info to A1 this destination. The next four lines of code are defined as A1.

About the Appender output destination, output format, such as the detailed definition, you can Google, here is not described in detail.

Log4j three important parts: the priority of the log information, the output destination of the log information, the output format of the log information.

2. Web.xml Configuration

	<context-param>
   		<param-name>log4jConfigLocation</param-name> 
   		<param-value> web-inf/log4j.properties</param-value> 
	</context-param>
	<context-param> 
   		< param-name>log4jrefreshinterval</param-name> 
   		<param-value>60000</param-value> 
	</context-param> 
	<!--need to add Spring-web.jar package, otherwise error message-->
	<listener> 
   		< Listener-class>org.springframework.web.util.log4jconfiglistener</listener-class> 
	

The first parameter defines the location of the log4j configuration file, the second parameter defines the refresh cycle, and the log4j configuration file is modified without redeployment. Behind the listener, the Spring-web.jar package must be included in the Project project.

3. Call

In the class that requires log output, define the log object

Private final Logger Logger = Logger.getlogger ("Operatelog");

Where Operatelog is a custom log name that can be defined and used as needed.

Used where output logs are required

 logger.info (Session.getattribute ("user") + "login System");

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.