log4j default is to keep the log content appended to the log file;
Here is a property Append default is true;
If we set false to not append directly overwrite the previous content;
Let's test it out:
Log4j.rootlogger=debug, Console, FIEL
#Console
Log4j.appender.console=org.apache.log4j.consoleappender
Log4j.appender.console.layout=org.apache.log4j.ttcclayout
#FIEL
Log4j.appender.FIEL = Org.apache.log4j.FileAppender
Log4j.appender.FIEL.File = C://log.log
Log4j.appender.FIEL.layout = Org.apache.log4j.PatternLayout
Log4j.appender.FIEL.layout.ConversionPattern =%d [%t]%-5p [%c]-%m%n
Log4j.appender.FIEL.Append = False
Changed to Append false.
Test class:
Package com.open1111; import Org.apache.log4j.Logger; Public classTest {Private StaticLogger Logger=logger.getlogger (Test.class);//Get Logger instance Public Static voidMain (string[] args) {Logger.info ("General Info Info"); Logger.debug ("Debugging Debug Information"); Logger.error ("Error Message"); Logger.warn ("warning warn information"); Logger.fatal ("fatal error fatal information"); Logger.error ("error Message",NewIllegalArgumentException ("Illegal parameters")); } }
The first time we performed:
We modified the test code:
Package com.open1111; import Org.apache.log4j.Logger; Public classTest {Private StaticLogger Logger=logger.getlogger (Test.class);//Get Logger instance Public Static voidMain (string[] args) {Logger.info ("General Info Info 22222222222222"); Logger.debug ("Debugging Debug Information"); Logger.error ("Error Message"); Logger.warn ("warning warn information"); Logger.fatal ("fatal error fatal information"); Logger.error ("error message 222222222222222",NewIllegalArgumentException ("Illegal parameters")); } }
By default Append True
is appended, we append here false
The result is an overlay of the previous
OK This property we understand can use the default true;
Log4j Append property specifies whether to append content