一、问题描述
log4cxx是C++常用的开源日志库,是Apache的又一扛鼎力作。
log4cxx使用Apache License Version 2.0,允许商业化使用和分发代码,同时保留了代码的开源特性和使用自由。
使用过程中如果发现报错,log4cxx: Large window sizes are not allowed.
二、源码分析
通过关键字搜索代码:
fixedwindowrollingpolicy.cpp
void FixedWindowRollingPolicy::activateOptions(Pool& p) {
RollingPolicyBase::activateOptions(p);
if (maxIndex < minIndex) {
LogLog::warn(
LOG4CXX_STR("MaxIndex cannot be smaller than MinIndex."));
maxIndex = minIndex;
}
if ((maxIndex - minIndex) > MAX_WINDOW_SIZE) {
LogLog::warn(LOG4CXX_STR("Large window sizes are not allowed."));
maxIndex = minIndex + MAX_WINDOW_SIZE;
}
PatternConverterPtr itc = getIntegerPatternConverter();
if (itc == NULL) {
throw IllegalStateException();
}
}
fixedwindowrollingpolicy.h
* <p>Given that this rollover algorithm requires as many file renaming
* operations as the window size, large window sizes are discouraged. The
* current implementation will automatically reduce the window size to 12 when
* larger values are specified by the user.
/**
* It's almost always a bad idea to have a large window size, say over 12.
*/
enum { MAX_WINDOW_SIZE = 12 };
Breakpoint 3, log4cxx::rolling::FixedWindowRollingPolicy::activateOptions (this=0x128ec10, p=...)
at fixedwindowrollingpolicy.cpp:76
76 RollingPolicyBase::activateOptions(p);
(gdb) p maxIndex
$1 = 20
(gdb) p minIndex
$2 = 1
代码注释很清楚,maxIndex减minIndex的差值最好不要大于12。即使用户设置的值超出范围,log4cxx内部也会减少。
三、结论
通过阅读源代码,发现log.xml的配置项MaxBackupIndex就是maxIndex,改为13即可。
<param name="MaxBackupIndex" value="13" />
MaxBackupIndex与log4cxx最大生成日志文件的个数有关,如:
log.log
log.log.1
log.log.10
log.log.11
log.log.12
log.log.13
log.log.2
log.log.3
log.log.4
log.log.5
log.log.6
log.log.7
log.log.8
log.log.9