Log4cxx中的RollingFileAppender

如果是比较老的0.9.7版本,使用如下的配置文件就OK:
log4j.rootLogger=debug, R
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=test.log
log4j.appender.R.MaxFileSize=10KB
log4j.appender.R.MaxBackupIndex=5
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d{%y.%m.%d %H:%M:%S} %p %c – %m%n

如果是直接从版本库中取出的head revision,上面的配置文件就不起作用了,超过指定大小也不会roll,但使用xml格式的配置文件是没问题的,如:
<?xml version=”1.0″ encoding=”UTF-8″ ?>
<log4j:configuration xmlns:log4j=’http://logging.apache.org/’ debug=”true”>
<appender name=”ROLLING” class=”org.apache.log4j.rolling.RollingFileAppender”>
<rollingPolicy class=”org.apache.log4j.rolling.FixedWindowRollingPolicy”>
<param name=”fileNamePattern” value=”test.log.%i”/>
<param name=”minIndex” value=”0″/>
<param name=”maxIndex” value=”2″/>
</rollingPolicy>
<triggeringPolicy class=”org.apache.log4j.rolling.SizeBasedTriggeringPolicy”>
<param name=”MaxFileSize” value=”10000″ />
</triggeringPolicy>
<layout class=”org.apache.log4j.PatternLayout”>
<param name=”ConversionPattern” value=”%d{%y.%m.%d %H:%M:%S} %p %c – %m%n”/>
</layout>
<param name=”file” value=”test.log”/>
<param name=”append” value=”true”/>
</appender>
<root>
<level value=”info”/>
<appender-ref ref=”ROLLING”/>
</root>
</log4j:configuration>

试着仿照上面的内容写了一个properties文件,仍然没有roll的效果,原因不详。

后续报导:
官方网站有个相关的Patch:LOGCXX-102

This entry was posted in 软件开发 and tagged . Bookmark the permalink.

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s