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:
1234567891011121314151617181920 |
package
com.open1111;
import
org.apache.log4j.Logger;
public
class
Test {
private
static
Logger logger=Logger.getLogger(Test.
class
);
// 获取logger实例
public
static
void
main(String[] args) {
logger.info(
"普通Info信息"
);
logger.debug(
"调试debug信息"
);
logger.error(
"报错error信息"
);
logger.warn(
"警告warn信息"
);
logger.fatal(
"严重错误fatal信息"
);
logger.error(
"报错信息"
,
new
IllegalArgumentException(
"非法参数"
));
}
}
|
The first time we performed:
We modified the test code:
1234567891011121314151617181920 |
package
com.open1111;
import
org.apache.log4j.Logger;
public class
Test {
private
static
Logger logger=Logger.getLogger(Test.
class
);
// 获取logger实例
public
static
void main(String[] args) {
logger.info(
"普通Info信息22222222222222"
);
logger.debug(
"调试debug信息"
);
logger.error(
"报错error信息"
);
logger.warn(
"警告warn信息"
);
logger.fatal(
"严重错误fatal信息"
);
logger.error(
"报错信息222222222222222"
,
new
IllegalArgumentException(
"非法参数"
));
}
}
|
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