#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">
        <Property name="LOG_PATTERN">
            [ %d{yyyy-MMM-dd HH:mm:ss a} ] - [%t] %-5level %logger{36} - %msg%n
        <Console name="ConsoleAppender" target="SYSTEM_OUT" follow="true">
            <PatternLayout pattern="${LOG_PATTERN}"/>
        <RollingFile name="FileAppender" fileName="/home/ec2-user/apps/wc-notification-service/wc-notification.out"
                <SizeBasedTriggeringPolicy size="1MB" />
                <Delete basePath="logs" maxDepth="1">
                    <IfFileName glob="wc-notification.out-*.log" />
                    <IfLastModified age="1m" />
        <Root level="info">
            <!--<AppenderRef ref="ConsoleAppender" /> -->
            <AppenderRef ref="FileAppender" />

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.