如果希望为日志加一个时间戳,则可以通过下面的方式来配置:
<configuration>
<!-- Insert the current time formatted as "yyyyMMdd'T'HHmmss" under
the key "bySecond" into the logger context. This value will be
available to all subsequent configuration elements. -->
<timestamp key="bySecond" datePattern="yyyyMMdd'T'HHmmss"/>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<!-- use the previously created timestamp to create a uniquely
named log file -->
<file>log-${bySecond}.txt</file>
<encoder>
<pattern>%logger{35} - %msg%n</pattern>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="FILE" />
</root>
</configuration>
<timestamp>标签有两个必要的属性,分别是 name 和 datePattern,还有一个可选的属性 timeReference,name 所指定的可以用来作为变量使用,dataPattern 的格式与 SimpleDateFormat 的格式一样,而 timeReference 默认是配置文件被解析的时间,也可以显式指定为 contextBirth,这样时间就是上下文被创建的时间。
如下例子:
<configuration>
<timestamp key="bySecond" datePattern="yyyyMMdd'T'HHmmss"
timeReference="contextBirth"/>
...
</configuration>
RollingFileAppender 既可以记录日志到文件,也可以在某个条件到达后,转移到另外一个文件。有两个子组件,分别是 RollingPolicy 和 TriggeringPolicy,分别描述了如何滚动,以及何时滚动。
属性:
属性名类型描述
FixedWindowRollingPolicy 不支持 prudent 模式。TimeBasedRollingPolicy 支持 prudent 模式,不过有两个限制。fileappender rollover在 prudent 模式下,无法进行文件压缩,file 属性必须留白,不能填写。
RollingPolicy 主要负责文件的移动和重命名
package ch.qos.logback.core.rolling;
import ch.qos.logback.core.FileAppender;
import ch.qos.logback.core.spi.LifeCycle;
public intece RollingPolicy extends LifeCycle {
public void rollover() throws RolloverFailure;
public String getActiveFileName();
public CompressionMode getCompressionMode();
public void setParent(FileAppender appender);
}
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-32110-3.html
好有范
那个密封的包装袋的空气就够蛆活几个月了