Log4j Log sub-module printing without printing to the console

Source: Internet
Author: User

Due to the activation of the Timer refresh program, a large number of logs are made in the Catalina.out configuration file, which makes the program difficult to debug. The log cannot be viewed properly. Therefore, the customer requests that the performance traffic configuration log be migrated out of the Catalina.out directory.           After modifying the log4j configuration file, the log output is found in the sub-file, but the performance traffic log output is still available in the Catalina.out file. The original configuration method is as follows:

          Log4j.logger.com.test.cao.snmpgather = INFO, Snmpgather

          log4j.appender.snmpgather= Org.apache.log4j.DailyRollingFileAppender

          log4j.appender.snmpgather.file=${catalina.home}/logs/performance /snmpgather_

          log4j.appender.snmpgather.datepattern= yyyy-mm-dd '. Log '

          log4j.appender.snmpgather.layout= Org.apache.log4j.PatternLayout

          log4j.appender.snmpgather.layout.conversionpattern=%-d{yyyy-mm-dd HH:mm:ss, SSS} [%p] [%c.%m:%l]%m%n
Later found the following method, you can remove the log from the Catalina.out Workbench log file, log4j.additivity the current configuration file as follows:
          Log4j.logger.com.test.cao.snmpgather = INFO, Snmpgather

          log4j.appender.snmpgather= Org.apache.log4j.DailyRollingFileAppender

          log4j.appender.snmpgather.file=${catalina.home}/logs/performance /snmpgather_

          log4j.appender.snmpgather.datepattern= yyyy-mm-dd '. Log '

          log4j.appender.snmpgather.layout= Org.apache.log4j.PatternLayout

          log4j.appender.snmpgather.layout.conversionpattern=%-d{yyyy-mm-dd HH:mm:ss, SSS} [%p] [%c.%m:%l]%m%n
	  Log4j.additivity.com.linkage.module.liposs.system.cao.snmpgather = False
Here is log4j.additivity explanation: Log4j.additivity is the flag bit of whether the child logger inherits the output source (Appender) of the parent logger.
Specifically, by default, logger inherits the Appender of the parent logger, which means that the logger is output in the logger of the parent appender.
If Additivity is set to false, the child logger will only output in its own appender, not in the appender of the parent logger. Because the parent log is:
          log4j.rootcategory=, A1, R

          log4j.appender.a1=org.apache.log4j.consoleappender

          Log4j.appender.a1.threshold=info

          log4j.appender.a1.layout=org.apache.log4j.patternlayout

          log4j.appender.a1.layout.conversionpattern=%-d{yyyy-mm-dd HH:mm:ss} [%c]-[%p]%m%n

          log4j.appender.r.threshold =info

          log4j.appender.r.maxfilesize=100kb

          log4j.appender.r.maxbackupindex=10

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

          log4j.appender.r.layout.conversionpattern=%p%t%c-%m %n
So it hits the workbench. Setting Additivity to False relies only on its own configuration.

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.