簡體   English   中英

Log4j2-創建新的日志文件

[英]Log4j2 - create new log file

我已經配置了將日志保存到文件的功能,但是日志會追加到現有內容中。 我想創建總是新文件。 我怎樣才能做到這一點?

我的log4j2.xml:

    <?xml version="1.0" encoding="UTF-8"?>
<Configuration>
    <Appenders>
        <File name="File" fileName="out.log">
            <PatternLayout pattern="[%d{ISO8601} %-5level] %logger{36} - %msg%n"/>
        </File>
    </Appenders>
    <Loggers>
        <Root level="error">
            <AppenderRef ref="File"/>
        </Root>
        <Root level="info">
            <AppenderRef ref="File"/>
        </Root>
    </Loggers>
</Configuration>

FileAppender具有一個名為append的屬性,該屬性的默認值為true ,因此請按以下方式進行配置:

<File name="File" fileName="out.log" append="false">

可以在https://logging.apache.org/log4j/2.x/manual/appenders.html#FileAppender中找到文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM