Search in sources :

Example 1 with SizeBasedTriggeringPolicy

use of org.apache.log4j.rolling.SizeBasedTriggeringPolicy in project tray by qzind.

the class PrintSocketServer method setupFileLogging.

public static void setupFileLogging() {
    FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
    rollingPolicy.setFileNamePattern(SystemUtilities.getDataDirectory() + File.separator + Constants.LOG_FILE + ".log.%i");
    rollingPolicy.setMaxIndex(Constants.LOG_ROTATIONS);
    SizeBasedTriggeringPolicy triggeringPolicy = new SizeBasedTriggeringPolicy(Constants.LOG_SIZE);
    RollingFileAppender fileAppender = new RollingFileAppender();
    fileAppender.setLayout(new PatternLayout("%d{ISO8601} [%p] %m%n"));
    fileAppender.setThreshold(Level.DEBUG);
    fileAppender.setFile(SystemUtilities.getDataDirectory() + File.separator + Constants.LOG_FILE + ".log");
    fileAppender.setRollingPolicy(rollingPolicy);
    fileAppender.setTriggeringPolicy(triggeringPolicy);
    fileAppender.setEncoding("UTF-8");
    fileAppender.setImmediateFlush(true);
    fileAppender.activateOptions();
    org.apache.log4j.Logger.getRootLogger().addAppender(fileAppender);
}
Also used : FixedWindowRollingPolicy(org.apache.log4j.rolling.FixedWindowRollingPolicy) RollingFileAppender(org.apache.log4j.rolling.RollingFileAppender) PatternLayout(org.apache.log4j.PatternLayout) SizeBasedTriggeringPolicy(org.apache.log4j.rolling.SizeBasedTriggeringPolicy)

Aggregations

PatternLayout (org.apache.log4j.PatternLayout)1 FixedWindowRollingPolicy (org.apache.log4j.rolling.FixedWindowRollingPolicy)1 RollingFileAppender (org.apache.log4j.rolling.RollingFileAppender)1 SizeBasedTriggeringPolicy (org.apache.log4j.rolling.SizeBasedTriggeringPolicy)1