log4cxx: Large window sizes are not allowed.

一、问题描述

        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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值