log4j output log to file [configuration]

Source: Internet
Author: User
Tags log4j

Log4j.properties:

Log4j.rootlogger=debug,console,file

Log4j.appender.console=org.apache.log4j.consoleappender
Log4j.appender.console.threshold=info
log4j.appender.console.layout=org.apache.log4j.patternlayout
Log4j.appender.console.layout.conversionpattern=%d{yyyy-mm-dd HH:MM:SS} [%5p]-%c-%f (%l)-%m%n

Log4j.appender.file=org.apache.log4j.rollingfileappender
log4j.appender.file.append=true
Log4j.appender.file.file=.. /logs/log4jtest.log
log4j.appender.file.threshold=info
log4j.appender.file.layout= Org.apache.log4j.PatternLayout
log4j.appender.file.layout.conversionpattern=%d{yyyy-mm-dd HH:mm:ss} [%5p]-%c -%f (%l)-%m%n
LOG4J.APPENDER.FILE.MAXFILESIZE=10MB

The default is to place the log4j.properties in the classpath. Save the log file to the $tomcat_home/logs directory

Initializing the logger in the business class

private static Logger log = Logger.getlogger (Logoutservlet.class);
Print Log

Log.info ("User [" +username+ "] is logout");





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.