Search in sources :

Example 1 with SizeRotatingFileHandler

use of org.jboss.logmanager.handlers.SizeRotatingFileHandler in project quarkus by quarkusio.

the class SizeRotatingLoggingTest method sizeRotatingConfigurationTest.

@Test
public void sizeRotatingConfigurationTest() {
    Handler handler = getHandler(SizeRotatingFileHandler.class);
    assertThat(handler.getLevel()).isEqualTo(Level.INFO);
    Formatter formatter = handler.getFormatter();
    assertThat(formatter).isInstanceOf(PatternFormatter.class);
    PatternFormatter patternFormatter = (PatternFormatter) formatter;
    assertThat(patternFormatter.getPattern()).isEqualTo("%d{HH:mm:ss} %-5p [%c{2.}]] (%t) %s%e%n");
    SizeRotatingFileHandler sizeRotatingFileHandler = (SizeRotatingFileHandler) handler;
    assertThat(sizeRotatingFileHandler.isRotateOnBoot()).isTrue();
}
Also used : PatternFormatter(org.jboss.logmanager.formatters.PatternFormatter) Formatter(java.util.logging.Formatter) SizeRotatingFileHandler(org.jboss.logmanager.handlers.SizeRotatingFileHandler) Handler(java.util.logging.Handler) LoggingTestsHelper.getHandler(io.quarkus.logging.LoggingTestsHelper.getHandler) PatternFormatter(org.jboss.logmanager.formatters.PatternFormatter) SizeRotatingFileHandler(org.jboss.logmanager.handlers.SizeRotatingFileHandler) Test(org.junit.jupiter.api.Test) QuarkusUnitTest(io.quarkus.test.QuarkusUnitTest)

Example 2 with SizeRotatingFileHandler

use of org.jboss.logmanager.handlers.SizeRotatingFileHandler in project quarkus by quarkusio.

the class LoggingSetupRecorder method configureFileHandler.

private static Handler configureFileHandler(final FileConfig config, final ErrorManager errorManager, final LogCleanupFilter cleanupFilter) {
    FileHandler handler;
    FileConfig.RotationConfig rotationConfig = config.rotation;
    if (rotationConfig.fileSuffix.isPresent()) {
        PeriodicSizeRotatingFileHandler periodicSizeRotatingFileHandler = new PeriodicSizeRotatingFileHandler();
        periodicSizeRotatingFileHandler.setSuffix(rotationConfig.fileSuffix.get());
        periodicSizeRotatingFileHandler.setRotateSize(rotationConfig.maxFileSize.asLongValue());
        periodicSizeRotatingFileHandler.setRotateOnBoot(rotationConfig.rotateOnBoot);
        periodicSizeRotatingFileHandler.setMaxBackupIndex(rotationConfig.maxBackupIndex);
        handler = periodicSizeRotatingFileHandler;
    } else {
        SizeRotatingFileHandler sizeRotatingFileHandler = new SizeRotatingFileHandler(rotationConfig.maxFileSize.asLongValue(), rotationConfig.maxBackupIndex);
        sizeRotatingFileHandler.setRotateOnBoot(rotationConfig.rotateOnBoot);
        handler = sizeRotatingFileHandler;
    }
    final PatternFormatter formatter = new PatternFormatter(config.format);
    handler.setFormatter(formatter);
    handler.setAppend(true);
    try {
        handler.setFile(config.path);
    } catch (FileNotFoundException e) {
        errorManager.error("Failed to set log file", e, ErrorManager.OPEN_FAILURE);
    }
    handler.setErrorManager(errorManager);
    handler.setLevel(config.level);
    handler.setFilter(cleanupFilter);
    if (config.async.enable) {
        return createAsyncHandler(config.async, config.level, handler);
    }
    return handler;
}
Also used : PeriodicSizeRotatingFileHandler(org.jboss.logmanager.handlers.PeriodicSizeRotatingFileHandler) FileNotFoundException(java.io.FileNotFoundException) PatternFormatter(org.jboss.logmanager.formatters.PatternFormatter) ColorPatternFormatter(org.jboss.logmanager.formatters.ColorPatternFormatter) FileHandler(org.jboss.logmanager.handlers.FileHandler) PeriodicSizeRotatingFileHandler(org.jboss.logmanager.handlers.PeriodicSizeRotatingFileHandler) SizeRotatingFileHandler(org.jboss.logmanager.handlers.SizeRotatingFileHandler) PeriodicSizeRotatingFileHandler(org.jboss.logmanager.handlers.PeriodicSizeRotatingFileHandler) SizeRotatingFileHandler(org.jboss.logmanager.handlers.SizeRotatingFileHandler)

Aggregations

PatternFormatter (org.jboss.logmanager.formatters.PatternFormatter)2 SizeRotatingFileHandler (org.jboss.logmanager.handlers.SizeRotatingFileHandler)2 LoggingTestsHelper.getHandler (io.quarkus.logging.LoggingTestsHelper.getHandler)1 QuarkusUnitTest (io.quarkus.test.QuarkusUnitTest)1 FileNotFoundException (java.io.FileNotFoundException)1 Formatter (java.util.logging.Formatter)1 Handler (java.util.logging.Handler)1 ColorPatternFormatter (org.jboss.logmanager.formatters.ColorPatternFormatter)1 FileHandler (org.jboss.logmanager.handlers.FileHandler)1 PeriodicSizeRotatingFileHandler (org.jboss.logmanager.handlers.PeriodicSizeRotatingFileHandler)1 Test (org.junit.jupiter.api.Test)1