LOG4J configuration file configuration Specifies the package information output to the specified file

Source: Internet
Author: User
Tags log4j

Search on the internet for more than n data, basic are basic configuration and detailed introduction, reproduced too much, but caused us to search the key information more trouble, after a Google and their own debugging, finally succeeded, recorded.

Suppose I need to output the log information in the Com.domain.web.monitor package to ... /logs/a.log, configure the following

#monitor是我们单独配置的com. The appendname of Domain.web.monitor

Log4j.rootlogger=error,stdout,file,monitor

#这个是为单独的包设置AppendName并且日志级别.

Log4j.logger.com.ct10000.web.monitor=error,monitor

#将所有的日志信息全部输出到后台界面上

Log4j.appender.stdout=org.apache.log4j.consoleappender

log4j.appender.stdout.layout=org.apache.log4j.patternlayouthh:mm:ss}%p[priority]%n%x[ndc]%n%t[thread]%n%c[ category]%n%m[message]%n%n

LOG4J.APPENDER.STDOUT.LAYOUT.CONVERSIONPATTERN=[%5P]%D{YYYY-MM-DD hh:mm:ss}[%c] (%F:%L)%n%m%n%n

#配置com. Domain.web.monitor appendname, output to. In the/logs/a.log.

Log4j.appender.monitor=org.apache.log4j.rollingfileappender

Log4j.appender.monitor.file=.. /logs/a.log

log4j.appender.monitor.maxfilesize=10000kb

log4j.appender.monitor.maxbackupindex=10

Log4j.appender.monitor.append=true

Log4j.appender.monitor.layout=org.apache.log4j.patternlayout

#log4j. appender.monitor.layout.conversionpattern=[start]%d{yyyy/mm/dd/hh:mm:ss}[date]%n%p[priority]%n%x[ndc]%n %t[thread]%n%c[category]%n%m[message]%n%n

LOG4J.APPENDER.MONITOR.LAYOUT.CONVERSIONPATTERN=[%5P]%D{YYYY-MM-DD hh:mm:ss}[%c] (%F:%L)%n%m%n%n

#其余的日志信息输出到. In the/logs/b.log.

Log4j.appender.file=org.apache.log4j.rollingfileappender

Log4j.appender.file.file=.. /logs/b.log

log4j.appender.file.maxfilesize=10000kb

log4j.appender.file.maxbackupindex=10

Log4j.appender.file.append=true

Log4j.appender.file.layout=org.apache.log4j.patternlayout

#log4j. appender.file.layout.conversionpattern=[start]%d{yyyy/mm/dd/hh:mm:ss}[date]%n%p[priority]%n%x[ndc]%n%t[ thread]%n%c[category]%n%m[message]%n%n

LOG4J.APPENDER.FILE.LAYOUT.CONVERSIONPATTERN=[%5P]%D{YYYY-MM-DD hh:mm:ss}[%c] (%F:%L)%n%m%n%n

By the way, I recommend several reliable articles on log4j:

Reference: http://blog.csdn.net/ziruobing/archive/2009/02/22/3919501.aspx (slow to open)

Http://dev.firnow.com/course/3_program/java/javajs/20090304/157547.html (detailed explanation of each parameter, feel not all, but enough)

Of course, this is to solve the problem after the record, not a complete tutorial, there are errors hope to guide.

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.