哪种方法实际在log4j2中执行滚动



我想知道哪种方法实际执行log4j2中文件的滚动。我试着在源代码中搜索它,但找不到

DefaultRolloverStrategy类中有一个方法public RolloverDescription rollover(final RollingFileManager manager),我在CustomStrategy类中重写了它,结果发现这个方法没有执行实际的滚动。

有人能帮我吗?

您要查找的实际上是RolloverDescription,它包含两种类型的操作:

AsyncAction-在关闭当前活动日志文件之后和下一次滚动尝试之前要完成的操作,可以异步执行。

SyncAction-在关闭当前活动日志文件之后,在将控制权返回给调用方之前要完成的操作。

执行这些操作的部分是RollingFileManager.rollover

final RolloverDescription descriptor = strategy.rollover(this);
if (descriptor != null) {
writeFooter();
closeOutputStream();
if (descriptor.getSynchronous() != null) {
LOGGER.debug("RollingFileManager executing synchronous {}", descriptor.getSynchronous());
try {
success = descriptor.getSynchronous().execute();
} catch (final Exception ex) {
success = false;
logError("Caught error in synchronous task", ex);
}
}
if (success && descriptor.getAsynchronous() != null) {
LOGGER.debug("RollingFileManager executing async {}", descriptor.getAsynchronous());
asyncExecutor.execute(new AsyncAction(descriptor.getAsynchronous(), this));
releaseRequired = false;
}
return true;
}

因此,您的CustomStrategy.rerolling就是上面代码片段的第一行中发生的内容。CustomStrategy.rollover返回RolloverDescription,它包含要执行的操作,正如我上面解释的那样。

最新更新