log4j output to more than one custom file log4j output to multiple custom files

Source: Internet
Author: User
The powerful function of log4j is unquestionable, but in practical application it is unavoidable to have a function to output independent log files, how to separate the required content from the original log, and form a separate log file. In fact, as long as the existing log4j based on a little configuration can easily achieve this function.
<span style= "FONT-SIZE:24PX;"  
>log4j.rootlogger=info,logfile # Set Log for Dao,service class Log4j.logger.com.dong.dao=error,mydao
log4j.logger.com.dong.service= Error,myservice Log4j.appender.logfile=org.apache.log4j.consoleappender #控制台输出日志 Log4j.appender.logfile.layout=org.apache.log4j.patternlayout log4j.appender.logfile.layout.conversionpattern=%m %n # Service Settings Log4j.appender.myservice=org.apache.log4j.rollingfileappender #按天记录日志 log4j.appender.myService.File =/usr/tmp/logs/service.log log4j.appender.myservice.maxfilesize=50000kb log4j.appender.myservice.maxbackupindex= 1 log4j.appender.myservice.layout=org.apache.log4j.htmllayout log4j.additivity.loopPriceCalendarEntry =false #  
The log for the Com.dong.service class is entered only into the Service.log file Log4j.appender.mydao=org.apache.log4j.rollingfileappender  
Log4j.appender.mydao.file=/usr/tmp/logs/dao.log log4j.appender.mydao.maxfilesize=50000kb Log4j.appender.mydao.maxbackupindex=1 Log4j.appender.mydao.layout=org.apache.log4j.patternlayout 
Log4j.appender.mydao.layout.conversionpattern=%d{yyyy-mm-ddhh:mm:ss}%5p[%t] (%f:%l)-%m%n</span> 



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.