Log4j2滚动文件句柄打开

时间:2015-01-30 12:25:47

标签: java log4j log4j2

当Log4j2滚动我的日志文件时,它会打开其中的一部分我可以在lsof中看到:

java       6684      root  609u      REG        8,3      5791     142217 /jboss/server/all/log/info.log.2015-01-30 12:48-2.log (deleted)
java       6684      root  613r      REG        8,3      2917     140533 /jboss/server/all/log/info.log.2015-01-30 12:45-1.log (deleted)
java       6684      root  621u      REG        8,3     78090     140536 /jboss/server/all/log/service.manager.log.2015-01-30 12:46-1.log (deleted)
java       6684      root  622u      REG        8,3       309     140541 /jboss/server/all/log/info.log.2015-01-30 12:46-1.log (deleted)
java       6684      root  623u      REG        8,3       309     140539 /jboss/server/all/log/node.log.2015-01-30 12:46-1.log (deleted)
java       6684      root  644r      REG        8,3    126606     140228 /jboss/server/all/log/info.log.2015-01-30 12:44-1.log (deleted)
java       6684      root  648r      REG        8,3     70026     135612 /jboss/server/all/log/node.log.2015-01-30 12:44-1.log (deleted)
java       6684      root  649r      REG        8,3    126606     140202 /jboss/server/all/log/service.manager.log.2015-01-30 12:44-1.log (deleted)
java       6684      root  652r      REG        8,3      2917     140530 /jboss/server/all/log/node.log.2015-01-30 12:45-1.log (deleted)
java       6684      root  653r      REG        8,3    113366     140526 /jboss/server/all/log/service.manager.log.2015-01-30 12:45-1.log (deleted)
java       6684      root  654u      REG        8,3       322     140543 /jboss/server/all/log/service.manager.log.2015-01-30 12:47-1.log (deleted)

这是我的一个配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="trace">
    <Appenders>
        <RollingRandomAccessFile name="PCI" fileName="${sys:jboss.server.home.dir}}/log/mycast.pci.log"
                     filePattern="${sys:jboss.server.home.dir}}/log/mycast.pci.log.%d{yyyy-MM-dd HH:mm}-%i.log.gz">
            <param name="Threshold" value="trace" />
            <PatternLayout>
                <Pattern>%d %-5p [%c{1}] (%t) {%x}: %m%n</Pattern>
            </PatternLayout>
            <Policies>
                <TimeBasedTriggeringPolicy />
                <SizeBasedTriggeringPolicy size="32 MB"/>
            </Policies>
        </RollingRandomAccessFile>
    </Appenders>
    <Loggers>
        <Logger name="com.abc" level="trace">
            <AppenderRef ref="PCI" />
        </Logger>
    </Loggers>
</Configuration>

我按照Log4j2 Rolled Files that are deleted are still open and disk space not freed的建议尝试了RollingRandomAccessFileAppender,但我得到了:

RollingRandomAccessFileAppender: CLASS_NOT_FOUND

有没有办法告诉Log4j2在滚动之前或不使用一段时间后关闭文件?我应该使用其他滚筒吗?

由于

1 个答案:

答案 0 :(得分:0)

这看起来很奇怪:路径似乎并不完全匹配:

/jboss/server/all/log/info.log.2015-01-30 12:48-2.log(已删除)

文件名= “$ {SYS:jboss.server.home.dir}} /日志/ mycast.pci.log”                      filePattern =“$ {sys:jboss.server.home.dir}} / log / mycast.pci.log。%d {yyyy-MM-dd HH:mm} - %i.log.gz”&gt;

翻转路径有一个日期,但以“.gz”结尾,其中打开的文件句柄不以“.gz”结尾。

您是否尝试删除filePattern中的空格?