zoukankan      html  css  js  c++  java
  • Logback file属性 与 fileNamePattern属性的关系

    https://juejin.cn/post/6844903859865780231

    官方原文

    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属性

    1. 系统会将日志内容直接写入log/check.2019-06-04.log中。
    2. 在2019-06-05凌晨,系统会将日志内容直接写入log/check.2019-06-04.log

    总结

    仍以2019-06-04为例,如果你设置了File属性,当天你只能看到check.log日志文件,2019-06-05才会看到check.201-06-04.log文件。但是如果你忽略了,你当天就能看到check.2019-06-04.log文件,但你始终看不到check.log文件。


    作者:风吟空城
    链接:https://juejin.cn/post/6844903859865780231
    来源:掘金
    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
  • 相关阅读:
    idea开发工具关于svn上代码的颜色
    写一个Request包装类ExternalApiHttpServletRequestWrapper(外部接口请求使用用于解密)
    什么情况下,需要用事务?
    SpringBoot 2.1.6.RELEASE ->SpringCloudAlibaba
    oracle查看锁表进程,杀掉锁表进程
    JavaScript 闭包
    萤石云定时更新 accessToken
    Ubuntu Linux的DevExpressReport无法显示报表(.net core)
    Vue在IE下打开空白解决方案
    DFT scan chain 介绍
  • 原文地址:https://www.cnblogs.com/zkwarrior/p/14863959.html
Copyright © 2011-2022 走看看