Search in sources :

Example 1 with PeriodicSizeRotatingFileHandler

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

the class PeriodicSizeRotatingLoggingTest method periodicSizeRotatingConfigurationTest.

@Test
public void periodicSizeRotatingConfigurationTest() {
    Handler handler = getHandler(PeriodicSizeRotatingFileHandler.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");
    PeriodicSizeRotatingFileHandler periodicSizeRotatingFileHandler = (PeriodicSizeRotatingFileHandler) handler;
    assertThat(periodicSizeRotatingFileHandler.isRotateOnBoot()).isFalse();
}
Also used : PatternFormatter(org.jboss.logmanager.formatters.PatternFormatter) Formatter(java.util.logging.Formatter) PeriodicSizeRotatingFileHandler(org.jboss.logmanager.handlers.PeriodicSizeRotatingFileHandler) Handler(java.util.logging.Handler) PeriodicSizeRotatingFileHandler(org.jboss.logmanager.handlers.PeriodicSizeRotatingFileHandler) LoggingTestsHelper.getHandler(io.quarkus.logging.LoggingTestsHelper.getHandler) PatternFormatter(org.jboss.logmanager.formatters.PatternFormatter) Test(org.junit.jupiter.api.Test) QuarkusUnitTest(io.quarkus.test.QuarkusUnitTest)

Example 2 with PeriodicSizeRotatingFileHandler

use of org.jboss.logmanager.handlers.PeriodicSizeRotatingFileHandler 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)

Example 3 with PeriodicSizeRotatingFileHandler

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

the class PeriodicSizeRotatingLoggingRotateOnBootTest method periodicSizeRotatingConfigurationTest.

@Test
public void periodicSizeRotatingConfigurationTest() {
    Handler handler = getHandler(PeriodicSizeRotatingFileHandler.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");
    PeriodicSizeRotatingFileHandler periodicSizeRotatingFileHandler = (PeriodicSizeRotatingFileHandler) handler;
    assertThat(periodicSizeRotatingFileHandler.isRotateOnBoot()).isTrue();
}
Also used : PatternFormatter(org.jboss.logmanager.formatters.PatternFormatter) Formatter(java.util.logging.Formatter) PeriodicSizeRotatingFileHandler(org.jboss.logmanager.handlers.PeriodicSizeRotatingFileHandler) Handler(java.util.logging.Handler) PeriodicSizeRotatingFileHandler(org.jboss.logmanager.handlers.PeriodicSizeRotatingFileHandler) LoggingTestsHelper.getHandler(io.quarkus.logging.LoggingTestsHelper.getHandler) PatternFormatter(org.jboss.logmanager.formatters.PatternFormatter) Test(org.junit.jupiter.api.Test) QuarkusUnitTest(io.quarkus.test.QuarkusUnitTest)

Aggregations

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