【发布时间】:2015-07-26 12:40:13
【问题描述】:
为了实现this issue,即periodic-rotating-file-handler 的max-backup-index 功能,我试图了解max-backup-index 属性在size-rotating-file-handler 中的工作原理。
尝试
Wildfly 读取 xml 配置:
<size-rotating-file-handler name="FILE" autoflush="true">
<level name="INFO"/>
<formatter>
<pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
</formatter>
<file relative-to="jboss.server.log.dir" path="server.log"/>
<rotate-size value="100K"/>
<max-backup-index value="10"/>
<append value="true"/>
</size-rotating-file-handler>
如果日志文件的数量大于 10 个,Wildfly 将删除这些文件,直到剩下 10 个。
已查看驻留在 Github 上的 Wildfly 代码,以了解哪些代码负责读取 <max-backup-index value="10"/> sn-p 并删除多余的日志文件。
PeriodicSizeRotatingHandlerResourceDefinition
class PeriodicSizeRotatingHandlerResourceDefinition extends AbstractFileHandlerDefinition {
public static final String PERIODIC_SIZE_ROTATING_FILE_HANDLER = "periodic-size-rotating-file-handler";
static final PathElement PERIODIC_SIZE_ROTATING_HANDLER_PATH = PathElement.pathElement(PERIODIC_SIZE_ROTATING_FILE_HANDLER);
static final AttributeDefinition[] ATTRIBUTES = Logging.join(DEFAULT_ATTRIBUTES, AUTOFLUSH, APPEND, MAX_BACKUP_INDEX, ROTATE_SIZE, ROTATE_ON_BOOT, SUFFIX, NAMED_FORMATTER, FILE);
public PeriodicSizeRotatingHandlerResourceDefinition(final ResolvePathHandler resolvePathHandler) {
super(PERIODIC_SIZE_ROTATING_HANDLER_PATH, false, PeriodicSizeRotatingFileHandler.class, resolvePathHandler, ATTRIBUTES);
}
super 指的是超类的构造函数,即AbstractFileHandlerDefinition
abstract class AbstractFileHandlerDefinition extends AbstractHandlerDefinition {
protected AbstractFileHandlerDefinition(final PathElement path, final boolean registerLegacyOps,
final Class<? extends Handler> type,
final ResolvePathHandler resolvePathHandler,
final AttributeDefinition... attributes) {
super(path, registerLegacyOps, type, new DefaultPropertySorter(FileNameLastComparator.INSTANCE), attributes);
this.registerLegacyOps = registerLegacyOps;
this.resolvePathHandler = resolvePathHandler;
}
super 指的是AbstractHandlerDefinition
abstract class AbstractHandlerDefinition extends TransformerResourceDefinition {
protected AbstractHandlerDefinition(final PathElement path,
final boolean registerLegacyOps,
final Class<? extends Handler> type,
final PropertySorter propertySorter,
final AttributeDefinition[] attributes) {
this(path, registerLegacyOps, type, propertySorter, attributes, null, attributes);
}
目前的结果
此刻感觉就像我迷失在迷宫中。我找不到解释max-backup-index 属性和size-rotating-file-handler 之间交互的代码。
【问题讨论】:
标签: java xml oop logging wildfly