Logback file属性 与 fileNamePattern属性的关系

栏目: Java · 发布时间: 4年前

内容简介:以2019-06-04输出的日志为例,来解释下设置、忽略File属性的不同。
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.

翻译:

  1. RollingFileAppender的file属性可以设置,也可以忽略。
  2. 如果设置了 FileAppender 包含的属性 file ,系统实时生成的日志和根据日期生成的日志可以存储在不同的目录文件下。在这种情况下,系统实时生成的日志内容都会记录在 file 属性指定的文件中。因此,该日志文件名称不会随着时间的移动而更改。
  3. 如果忽略了 FileAppender 包含的属性 file ,活动文件的名字会根据 fileNamePattern 的值,每隔一段时间改变一次,即每隔一段时间会生成一个日志文件。

举例说明

<appender name="emergencyLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <!-- 写入日志内容的文件名称(目录) -->
    <File>log/check.log</File>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <!-- 活动文件的名字会根据fileNamePattern的值,每隔一段时间改变一次 -->
        <fileNamePattern>log/check.%d{yyyy-MM-dd}.log</fileNamePattern>
        <!-- 每产生一个日志文件,该日志文件的保存期限为30天 -->
        <maxHistory>30</maxHistory>
    </rollingPolicy>
    <encoder>
        <!-- pattern节点,用来设置日志的输入格式 -->
        <pattern>%d{yyyy-MM-dd HH:mm:ss} %-5level %logger [%msg]%n</pattern>
        <!-- 记录日志的编码:此处设置字符集 - -->
        <charset>UTF-8</charset>
    </encoder>
</appender>
复制代码

以2019-06-04输出的日志为例,来解释下设置、忽略File属性的不同。

设置File属性

  1. 系统会将日志内容全部写入 log/check.log 中。
  2. 在2019-06-05凌晨, check.log 会被重命名为 log/check.2019-06-04.log
  3. 然后再生成新的check.log文件,按照上面的步骤生成 log/check.2019-06-05.loglog/check.2019-06-06.log 等日志。

忽略File属性

log/check.2019-06-04.log
log/check.2019-06-04.log

以上所述就是小编给大家介绍的《Logback file属性 与 fileNamePattern属性的关系》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

HTML & XHTML

HTML & XHTML

Chuck Musciano、Bill Kennedy / O'Reilly Media / 2006-10-27 / GBP 39.99

"...lucid, in-depth descriptions of the behavior of every HTML tag on every major browser and platform, plus enough dry humor to make the book a pleasure to read." --Edward Mendelson, PC Magazine "Whe......一起来看看 《HTML & XHTML》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

html转js在线工具
html转js在线工具

html转js在线工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具