Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4j2 with MemoryMappedFile and break files

Is that possible to use MemoryMappedFile with Policies to break the files until fixed sizes, for example 250MB? My log4j2.xml is like this but I want to break the log files to 250MB and I need to use MemoryMappedFile for IO performance.

<Configuration monitorInterval="30">
    <Appenders>
        <MemoryMappedFile name="MemoryMap" fileName="output/jscsi-out.log">
            <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %c{2} - %m%n(%L)" />
            <Policies>
                <TimeBasedTriggeringPolicy />
                <SizeBasedTriggeringPolicy size="250 MB" />
            </Policies>
        </MemoryMappedFile>
    </Appenders>

    <Loggers>
        <Logger name="br.com" level="debug" additivity="false">
            <AppenderRef ref="MemoryMap" />
        </Logger>
        <Logger name="org.jscsi.target.TargetServer" level="debug"
            additivity="false">
            <AppenderRef ref="MemoryMap" />
        </Logger>
        <Logger name="org.jscsi.target.storage" level="info"
            additivity="false">
            <AppenderRef ref="MemoryMap" />
        </Logger>
        <Logger name="org.jscsi.service" level="debug" additivity="false">
            <AppenderRef ref="MemoryMap" />
        </Logger>
        <Root level="error" includeLocation="true">
            <AppenderRef ref="MemoryMap" />
        </Root>
    </Loggers>
</Configuration>
like image 324
Felipe Gutierrez Avatar asked Oct 23 '25 02:10

Felipe Gutierrez


1 Answers

(Background: I am the author of the MemoryMappedFile appender as well as Async Loggers.)

In some sense the MemoryMappedFile appender is still a work in progress (as of Log4j 2.5). As you mention, there is no Rolling variant. Also, I haven't been able to do any significant performance testing. I made a start some time ago but other issues took priority.

Initial performance testing indicates that synchronous logging, even when using the MemoryMappedFile appender, is unlikely to be faster than asynchronous logging via Async Loggers.

Generally, if you need the rollover behaviour I would suggest you use Async Loggers in combination with the RollingRandomAccessFile appender for now.

like image 89
Remko Popma Avatar answered Oct 25 '25 17:10

Remko Popma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!