Log4j Append property specifies whether to append content

Source: Internet
Author: User

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 packagecom.open1111;importorg.apache.log4j.Logger;publicclassTest {     privatestaticLogger logger=Logger.getLogger(Test.class); // 获取logger实例        publicstaticvoidmain(String[] args) {        logger.info("普通Info信息");        logger.debug("调试debug信息");        logger.error("报错error信息");        logger.warn("警告warn信息");        logger.fatal("严重错误fatal信息");                logger.error("报错信息"newIllegalArgumentException("非法参数"));            }    }

The first time we performed:

We modified the test code:

1234567891011121314151617181920 packagecom.open1111;importorg.apache.log4j.Logger;public classTest {    privatestaticLogger logger=Logger.getLogger(Test.class); // 获取logger实例        publicstaticvoid main(String[] args) {        logger.info("普通Info信息22222222222222");        logger.debug("调试debug信息");        logger.error("报错error信息");        logger.warn("警告warn信息");        logger.fatal("严重错误fatal信息");                logger.error("报错信息222222222222222"newIllegalArgumentException("非法参数"));            }    }

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

Related Article

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.