Log4j Learning (ii) different types of log output to different files

Source: Internet
Author: User

Purpose: One application has two different functions in the background service, we need to separate their logs, stored in 2 different log files.

WORKAROUND: You need to configure two different logger and corresponding appender in the Log4j.properties file

log4j.logger.logger1=debug,appender1log4j.appender.appender1=  Org.apache.log4j.FileAppenderlog4j.appender.appender1.File=c:/users/yang/desktop/  TestprojectLog1.loglog4j.appender.appender1.layout=org.apache.log4j.TTCCLayoutlog4j.logger.logger2 =Debug,appender2log4j.appender.appender2=  Org.apache.log4j.FileAppenderlog4j.appender.appender2.File=c:/users/yang/desktop/  TestprojectLog2.loglog4j.appender.appender2.layout=org.apache.log4j.ttcclayout

This is used in the code

Private Static Logger logger1 = Logger.getlogger ("Logger1"); Private Static Logger logger2 = Logger.getlogger ("Logger2");

Logger1.info ("-------------------Hello, world! to TestprojectLog1.log----------------------");
Logger2.info ("-------------------Hello, world! to TestprojectLog2.log----------------------");

The logs that get different logger1 and logger2 output will go to different files TestprojectLog1.log and TestprojectLog2.log.

Log4j Learning (ii) different types of log output to different files

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.