具有审慎标志和文件位置的Logback RollingFileAppender的设置 [英] Setup for a Logback RollingFileAppender with prudent flag and a file location

查看:630
本文介绍了具有审慎标志和文件位置的Logback RollingFileAppender的设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能在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

请注意,RollingFileAppender( 可以设置或省略TimeBasedRollingPolicy).通过设置 包含FileAppender的文件属性,您可以将 活动日志文件的位置和归档日志的位置 文件.当前日志将始终以指定的文件为目标 通过文件属性.因此,当前活动的名称 日志文件不会随时间变化.但是,如果您选择省略 文件属性,然后将为每个文件重新计算活动文件 期间,基于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 RollingFileAppender的设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆