Log4j-store logs in different paths

Source: Internet
Author: User

What if multiple log files need to be output in the same category? In fact, the truth is the same, first in Test. defined in java: private static Log logger1 = LogFactory. getLog ("myTest1"); private static Log logger2 = LogFactory. getLog ("myTest2"); then in log4j. add: log4j to properties. logger. myTest1 = DEBUG, test1log4j. appender. test1 = org. apache. log4j. fileAppenderlog4j. appender. test1.File =$ {myweb. root}/WEB-INF/log/test1.loglog4j. appender. test1.layout = org. apache. log4j. patternLayoutlog4j. appender. test1.layout. conver SionPattern = % d % p [% c]-% m % n log4j. logger. myTest2 = DEBUG, test2log4j. appender. test2 = org. apache. log4j. fileAppenderlog4j. appender. test2.File =$ {myweb. root}/WEB-INF/log/test2.loglog4j. appender. test2.layout = org. apache. log4j. patternLayoutlog4j. appender. test2.layout. conversionPattern = % d % p [% c]-% m % n, that is, a custom name (for example, "myTest1") for logger "), then in log4j. properties. Do not forget to use different logger for different logs (for example, logger1.info ("abc") for output to test1.log ")). Another problem is that these custom logs are output to the logs configured by log4j. rootLogger at the same time by default. How can they only be output to the specified logs? Don't worry. Here is a switch: log4j. additi.pdf. myTest1 = false it is used to set whether to output to log4j at the same time. in the logs configured by rootLogger, if it is set to false, it will not be output to other places! Note that "myTest1" here is the custom name you gave logger in the program! If you say that I just don't want to output this log to the logfile configured by log4j. rootLogger at the same time, I still want to output this log in stdout! Let's do it. Change your log4j. logger. myTest1 = DEBUG and test1 to the next step! Log4j. logger. myTest1 = DEBUG, test1, stdout

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.