问题描述
我怎样才能在Logback中创建一个RollingFileAppender
来接受审慎的标志,并允许我指定日志文件的位置?
How can I craete a RollingFileAppender
in Logback that accepts the prudent flag and also allows me to specifity the location of the log files?
我尝试了以下操作,但是据我了解,从文档登录中不支持file属性.还有另一种设置日志文件位置的方法吗?
I tried the following but as I understand from the documentation logback doesn't support the file property. Is there another way to set the log file location?
<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
属性不是必需的.同样重要的是,在审慎模式下,必须留空.
If the file
property is missing, the currently active log file will be inferred from the value of fileNamePattern
. Thus, the file
property is not mandatory. Just as importantly, in prudent mode it must be left blank.
以下是 fileNamePattern
这篇关于具有审慎标志和文件位置的Logback RollingFileAppender的设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!