为了落实this issue ,即max-backup-index
periodic-rotating-file-handler
的功能我试图了解 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"/>
片段并删除多余的日志文件。
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 指父类(super class)的构造函数,即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
.
最佳答案
您需要查看JBoss Log Manager不是野蝇。 WildFly 只是将所有事情委托(delegate)给日志管理器。具体来说,您要寻找的是 this .
也就是说,这是一个棘手的问题。没有一种可靠的方法来确定应删除哪些文件。使用日期后缀,您只能做出最佳猜测,这并不是很好。您不希望日志轮换删除您有意尝试保存的文件。
例如,假设您有一个 server.log.2015-01-01
和一个 server.log.2015-01-01.save
。你怎么知道只删除第一个?我们不想删除第二个,因为它可能被用户重命名。
还需要考虑性能。您不希望在运行复杂的文件匹配算法时发生阻塞。默认情况下,日志记录是阻塞的,因此任何尝试记录日志的代码都将被阻塞,直到轮换完成。
关于java - 如果配置了 "max-backup-index"属性,Wildfly如何知道需要删除多个文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30245099/