I want to disable the output to the console when logging to file. See config-file below:
log4j.rootLogger=info,stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L --- %m%n
log4j.category.FileLog=info,R
log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.File=E:\\temp\\FileLog
log4j.appender.R.Append = true
log4j.appender.R.DatePattern='.'yyyy-MM-dd'.log'
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%m[%d{MM-dd HH:mm:ss}]%n
when I using:
Logger.getLogger("FileLog").info("LogText-FileLog");
this log print to stdout
too,how can I disable it?
You can use `log4j.additivity.FileLog = false, that is the 'flag' you are looking for.
From the official log4j documentation:
The output of a log statement of logger C will go to all the appenders in C and its ancestors. This is the meaning of the term "appender additivity".
However, if an ancestor of logger C, say P, has the additivity flag set to false, then C's output will be directed to all the appenders in C and its ancestors upto and including P but not the appenders in any of the ancestors of P.
Loggers have their additivity flag set to true by default.
Removing "stdout" from your root logger (as proposed in other answers) might not be a solution, because I suppose you are still interested in that console logs in some cases.
remove stdout from here
log4j.rootLogger=info,stdout
To:
log4j.rootLogger=info
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With