gpt4 book ai didi

logback - 设置带有谨慎标志和文件位置的 Logback RollingFileAppender

转载 作者:行者123 更新时间:2023-12-01 10:56:22 26 4
gpt4 key购买 nike

我怎样才能创建一个 RollingFileAppender在接受谨慎标志的 Logback 中,还允许我指定日志文件的位置?

我尝试了以下操作,但正如我从文档中了解到的,logback 不支持 file 属性。还有另一种设置日志文件位置的方法吗?

   <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${MY_LOG_LOCATION_PROP}/logs/mylogfile.log</file>
<prudent>true</prudent>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>mylogfile-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
</rollingPolicy>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

最佳答案

如果file属性丢失,当前事件的日志文件将从 fileNamePattern 的值推断出来。 .因此,file属性(property)不是强制性的。同样重要的是,在谨慎模式下,它 必须留空。

以下是 fileNamePattern 文档中的相关引用。 :

Note that the file property in RollingFileAppender (the parent of TimeBasedRollingPolicy) can be either set or omitted. By setting the file property of the containing FileAppender, you can decouple the location of the active log file and the location of the archived log files. The current logs will be always targeted at the file specified by the file property. It follows that the name of the currently active log file will not change over time. However, if you choose to omit the file property, then the active file will be computed anew for each period based on the value of fileNamePattern. The examples below should clarify this point...

关于logback - 设置带有谨慎标志和文件位置的 Logback RollingFileAppender,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14963723/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com