The internet is very popular log4j configuration files, where the beginning of a paragraph is like this
Log4j.rootlogger=debug,console,a1,im
Log4j.addivity.org.apache=true # applies to console Log4j.appender.console=org.apache.log4j.consoleappender
Log4j.appender.threshold=debug Log4j.appender.console.target=system.out log4j.appender.console.layout= Org.apache.log4j.PatternLayout Log4j.appender.console.layout.conversionpattern=[framework]%d-%c-%-4r [%t]%-5%x-% m%n #log4j. Appender.console.layout.conversionpattern=[start]%d{date}[date]%n%p[pri Ty]%n%x[ndc]%n%t[thread] n%c[ category]%n%m[message]%n%n Log4j.addivity.org.apache=true
Log4j.addivity.org.apache=true Whether it's true/false, you'll find that the log output doesn't change anything.
The correct format should be:
Log4j.additivity.org.apache=true
The role of additivity is to children-logger whether to use Rootlogger configuration, such as an output terminal.
Examples are as follows:
Java code
public static void Main (string[] args) {for (int i = 0; I < 1000;i + +) Logger.debug ("Rollingfileappendertest:" + i);}
Log4j.perperties
Log4j.rootlogger=debug,stdout
Log4j.appender.stdout=org.apache.log4j.consoleappender
Log4j.appender.stdout.layout=org.apache.log4j.patternlayout
log4j.appender.stdout.layout.conversionpattern=%d%5p%t%c%m%l-%m%n
Log4j.logger.log4jdemo.rollingfileappenderdemo=debug,rollinglogfile
Log4j.additivity.log4jdemo.rollingfileappenderdemo=false
Log4j.appender.rollinglogfile=org.apache.log4j.rollingfileappender
Log4j.appender.rollinglogfile.append=true
Log4j.appender.rollinglogfile.file=rollinglogfile.log
log4j.appender.rollinglogfile.maxfilesize=200kb
log4j.appender.rollinglogfile.maxbackupindex=10
Log4j.appender.rollinglogfile.layout=org.apache.log4j.ttcclayout
If additivity is false, only one rollinglogfile.log log file is generated, and there is no log information output on the screen. If additivity is true, log information is displayed on the screen (because Rootlogger's log output terminal is a stdout-screen), and rollinglogfile.log log files are generated.
additivity defaults to True in log4j. This explains why there are times when a log message has multiple outputs on the screen.