fedor.belov
fedor.belov

Reputation: 23323

Stop logging if file size is larger than X mb

We've got heavy loaded system. If something doesn't work system generates MB of logs every minute. In a few minutes we already don't have source of the problem (because log files are limited by size)

Is it possible to stop logging if file size is larger than X mb? Does logback have this appender?

Upvotes: 0

Views: 507

Answers (2)

djechlin
djechlin

Reputation: 60778

The full solution would be to use a powerful logging endpoint that aggregates data for you. Logback is stateless and is not powerful enough to do this. logstash and loggly are two such services but there are many.

Upvotes: 0

flafoux
flafoux

Reputation: 2110

This post Rolling logback logs on filesize and time might answer your question :

<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>logFile.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <!-- daily rollover -->
         <fileNamePattern>logFile.%d{yyyy-MM-dd}.log</fileNamePattern>
        <timeBasedFileNamingAndTriggeringPolicy
            class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
            <!-- or whenever the file size reaches 50MB -->
            <maxFileSize>50MB</maxFileSize>
        </timeBasedFileNamingAndTriggeringPolicy>
        <!-- keep 30 days' worth of history -->
        <maxHistory>30</maxHistory>
    </rollingPolicy>

    <encoder>
  <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender> 

More infos

Upvotes: 1

Related Questions