#StackBounty: #java #spring-boot #maven #log4j2 Spring Boot Log4j2 configuration issue with log size maintenance

Bounty: 200

I have a spring boot application and using log4j2 to generate console and persists logs in a centos linux.

I wanted to maintain only 5mb of log files in archive.

But the problem is, my archived log files are 5mb in total. but my main console log which is saving in the main log file i.e wc-notification.out is going beyond 1mb.

so my disk gets full and it causes an issue.

The brute force method solution is:
whenever restarting(hard stop and start) my spring boot application, the log is cleared in from wc-notification.out.

my log4j2 configuration xml file:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO" monitorInterval="30">
    <Properties>
        <Property name="LOG_PATTERN">
            [ %d{yyyy-MMM-dd HH:mm:ss a} ] - [%t] %-5level %logger{36} - %msg%n
        </Property>
    </Properties>
    <Appenders>
        <Console name="ConsoleAppender" target="SYSTEM_OUT" follow="true">
            <PatternLayout pattern="${LOG_PATTERN}"/>
        </Console>
        <RollingFile name="FileAppender" fileName="/home/ec2-user/apps/wc-notification-service/wc-notification.out"
                     filePattern="/home/ec2-user/apps/wc-notification-service/archives_test/wc-notification.out-%d{yyyy-MM-dd}-%i">
            <PatternLayout>
                <Pattern>${LOG_PATTERN}</Pattern>
            </PatternLayout>
            <Policies>
                <SizeBasedTriggeringPolicy size="1MB" />
            </Policies>
            <DefaultRolloverStrategy>
                <Delete basePath="logs" maxDepth="1">
                    <IfFileName glob="wc-notification.out-*.log" />
                    <IfLastModified age="1m" />
                </Delete>
            </DefaultRolloverStrategy>
        </RollingFile>
    </Appenders>
    <Loggers>
        <Root level="info">
            <!--<AppenderRef ref="ConsoleAppender" /> -->
            <AppenderRef ref="FileAppender" />
        </Root>
    </Loggers>
</Configuration>

somehow, the files are in range of 1mb, and the roll strategy is working, it is deleting the file

but, my disk space is still occupied with the space. what can be the reason?


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.