Skip to content

Setting 0 to maximumFileSize #92

Open

Description

@MohamadDabboussi11

In the README it says that setting maximumFileSize to 0 should disable the file size limit, meaning a single file can grow without restriction. But in practice, what happens is that the logger starts creating a flood of files, each only a few bytes long — as if the max file size were literally being treated as 0 bytes. What I actually want is to ignore file size entirely and just rely on daily rolling, so that I get one log file per day.

Also on Android, setTotalSizeCap is assigned as an int, which means its maximum value is 2^31 - 1 (≈2.1 GB). Any value above this overflows into a negative number. When that happens, Logback’s rolling policy breaks and no log files are produced.

Example:

FileLogger.configure({
  maximumNumberOfFiles: 60,
  maximumFileSize: 200 * 1024 * 1024, // 200 MB
  dailyRolling: true,
});

This calculates maximumNumberOfFiles * maximumFileSize as ~12 GB, which doesn’t fit in an int. The overflowed negative value passed to setTotalSizeCap prevents log files from being created

Activity

  1. alois-beto commented on Jan 14, 2026

    @alois-beto
    Collaborator

    Thanks for reporting this bug. What I’m seeing is that maximumFileSize = 0 is not compatible with daily rolling: in the Android implementation :

    if (dailyRolling) {
    SizeAndTimeBasedRollingPolicy<ILoggingEvent> rollingPolicy = new SizeAndTimeBasedRollingPolicy<>();
    rollingPolicy.setContext(loggerContext);
    rollingPolicy.setFileNamePattern(logsDirectory + "/" + logPrefix + "-%d{yyyy-MM-dd}.%i.log");
    rollingPolicy.setMaxFileSize(new FileSize(maximumFileSize));
    rollingPolicy.setTotalSizeCap(new FileSize(maximumNumberOfFiles * maximumFileSize));
    rollingPolicy.setMaxHistory(maximumNumberOfFiles);
    rollingPolicy.setParent(rollingFileAppender);
    rollingPolicy.start();
    rollingFileAppender.setRollingPolicy(rollingPolicy);
    } else if (maximumFileSize > 0) {
    FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
    rollingPolicy.setContext(loggerContext);
    rollingPolicy.setFileNamePattern(logsDirectory + "/" + logPrefix + "-%i.log");
    rollingPolicy.setMinIndex(1);
    rollingPolicy.setMaxIndex(maximumNumberOfFiles);
    rollingPolicy.setParent(rollingFileAppender);
    rollingPolicy.start();
    rollingFileAppender.setRollingPolicy(rollingPolicy);
    SizeBasedTriggeringPolicy triggeringPolicy = new SizeBasedTriggeringPolicy();
    triggeringPolicy.setContext(loggerContext);
    triggeringPolicy.setMaxFileSize(new FileSize(maximumFileSize));
    triggeringPolicy.start();
    rollingFileAppender.setTriggeringPolicy(triggeringPolicy);
    }
    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setContext(loggerContext);
    encoder.setCharset(Charset.forName("UTF-8"));
    encoder.setPattern("%msg%n");
    encoder.start();

    when dailyRolling is enabled, maximumFileSize is effectively interpreted as 0 bytes, which leads to the flood of tiny files.

    So I think for now you should avoid using dailyRolling: true with maximumFileSize: 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions