Mykhailo Kramar
Mykhailo Kramar

Reputation: 61

Missing logs while using RollingFile appender log4j2.xml

This is my lo4j2.xml file

<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
    <Properties>
        <Property name="log.directory">${sys:jboss.server.log.dir}</Property>
        <Property name="log.filename">application</Property>
        <Property name="log.pattern">[%d{DEFAULT}] [%-5level] [%t] [%logger] [%X{AD.requestGUID}] %msg%n</Property>
    </Properties>
    <Appenders>
        <RollingFile name="File" fileName="${log.directory}/${log.filename}.log"
                     filePattern="${log.directory}/${log.filename}.log.%i.gz">
            <PatternLayout pattern="${log.pattern}"/>
            <Policies>
                <SizeBasedTriggeringPolicy size="100 MB"/>
            </Policies>
            <DefaultRolloverStrategy max="300"/>
        </RollingFile>
  </Appenders>
   <Loggers>
   <Root level="info">
            <AppenderRef ref="File"/>
        </Root>
    </Loggers>
</Configuration>

Every ~20 min I have ~2 min of missing logs. When I reduced SizeBasedTriggeringPolicy size to 20 MB I noticed that amount of missing logs also reduced. I think problem appear when application try to compress file, because when I used FileAppender when everything was written to one not compressed file I didn't have logs losses.

In log4j2 documentation https://logging.apache.org/log4j/2.x/manual/appenders.html#RollingFileAppender I found information about tempCompressedFilePattern --->The pattern of the file name of the archived log file during compression. I try to use it like this <DefaultRolloverStrategy max="300" tempCompressedFilePattern ="${log.directory}/temp.log"/> but no changes. Maybe I used not in correct way? Any ideas how to fix problem with missing logs. Thank you!

Upvotes: 1

Views: 893

Answers (0)

Related Questions