Logback file属性 与 fileNamePattern属性的关系

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

内容简介:以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属性的关系》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

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

编程算法新手自学手册

编程算法新手自学手册

管西京 / 机械工业 / 2012-1 / 69.80元

《编程算法新手自学手册》主要内容简介:算法是指在有限步骤内求解某一问题所使用的一组定义明确的规则。程序员都会看重数据结构和算法的作用,水平越高,就越能理解算法的重要性。算法不仅是运算工具,更是程序的灵魂。《编程算法新手自学手册》循序渐进、由浅入深地详细讲解了基于C语言算法的核心技术,并通过具体实例的实现过程演练了各个知识点的具体使用流程。全书共11章,分为4篇。1~2章是基础篇,介绍算法开发所必需......一起来看看 《编程算法新手自学手册》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

URL 编码/解码
URL 编码/解码

URL 编码/解码

SHA 加密
SHA 加密

SHA 加密工具