Java Log Rotate rotateLogs(File where, String basename, int max)

Here you can find the source of rotateLogs(File where, String basename, int max)

Description

rotate Logs

License

MIT License

Declaration

private static void rotateLogs(File where, String basename, int max) 

Method Source Code


//package com.java2s;
/*//w  w  w  . j a v  a2  s. c om
 * Utils.java - Copyright(c) 2013 Joe Pasqua
 * Provided under the MIT License. See the LICENSE file for details.
 * Created: Jul 8, 2013
 */

import java.io.File;

public class Main {
    private static void rotateLogs(File where, String basename, int max) {
        File logfile = new File(where, String.format("%s-%02d.log", basename, max));
        if (logfile.exists()) {
            logfile.delete();
        }
        if (max > 0) {
            File previous = new File(where, String.format("%s-%02d.log", basename, max - 1));
            if (previous.exists()) {
                previous.renameTo(logfile);
            }
            rotateLogs(where, basename, max - 1);
        }
    }
}

Related

  1. rotateLog()