From 4bd700a5f1f8af7ea54596178b75c24a7854460e Mon Sep 17 00:00:00 2001 From: Martin Kouba Date: Thu, 21 Apr 2022 16:46:44 +0200 Subject: [PATCH] Logging - set default value for quarkus.log.file.rotation.max-file-size - also change the default value for quarkus.log.file.rotation.max-backup-index --- .gitignore | 1 + .../io/quarkus/runtime/logging/FileConfig.java | 6 +++--- .../runtime/logging/LoggingSetupRecorder.java | 17 +++++------------ .../logging/CategoryConfiguredHandlerTest.java | 10 +++++++--- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 2ab436ff74c7f..bcf6f3fd6fe36 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,7 @@ ObjectStore docker/distroless/bazel-* /.apt_generated_tests/ quarkus.log +quarkus.log* replay_*.logß nbactions.xml nb-configuration.xml diff --git a/core/runtime/src/main/java/io/quarkus/runtime/logging/FileConfig.java b/core/runtime/src/main/java/io/quarkus/runtime/logging/FileConfig.java index 78bcdb7c7368c..5e9b9239daa78 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/logging/FileConfig.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/logging/FileConfig.java @@ -58,13 +58,13 @@ public static class RotationConfig { /** * The maximum file size of the log file after which a rotation is executed. */ - @ConfigItem(defaultValueDocumentation = "10") - Optional maxFileSize; + @ConfigItem(defaultValue = "10M") + MemorySize maxFileSize; /** * The maximum number of backups to keep. */ - @ConfigItem(defaultValue = "1") + @ConfigItem(defaultValue = "5") int maxBackupIndex; /** diff --git a/core/runtime/src/main/java/io/quarkus/runtime/logging/LoggingSetupRecorder.java b/core/runtime/src/main/java/io/quarkus/runtime/logging/LoggingSetupRecorder.java index 3e2affb05babd..4a17b72e49e09 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/logging/LoggingSetupRecorder.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/logging/LoggingSetupRecorder.java @@ -33,7 +33,6 @@ import org.jboss.logmanager.handlers.AsyncHandler; import org.jboss.logmanager.handlers.ConsoleHandler; import org.jboss.logmanager.handlers.FileHandler; -import org.jboss.logmanager.handlers.PeriodicRotatingFileHandler; import org.jboss.logmanager.handlers.PeriodicSizeRotatingFileHandler; import org.jboss.logmanager.handlers.SizeRotatingFileHandler; import org.jboss.logmanager.handlers.SyslogHandler; @@ -470,26 +469,20 @@ public void close() throws SecurityException { private static Handler configureFileHandler(final FileConfig config, final ErrorManager errorManager, final LogCleanupFilter cleanupFilter) { - FileHandler handler = new FileHandler(); + FileHandler handler; FileConfig.RotationConfig rotationConfig = config.rotation; - if ((rotationConfig.maxFileSize.isPresent() || rotationConfig.rotateOnBoot) - && rotationConfig.fileSuffix.isPresent()) { + if (rotationConfig.fileSuffix.isPresent()) { PeriodicSizeRotatingFileHandler periodicSizeRotatingFileHandler = new PeriodicSizeRotatingFileHandler(); periodicSizeRotatingFileHandler.setSuffix(rotationConfig.fileSuffix.get()); - rotationConfig.maxFileSize - .ifPresent(memorySize -> periodicSizeRotatingFileHandler.setRotateSize(memorySize.asLongValue())); + periodicSizeRotatingFileHandler.setRotateSize(rotationConfig.maxFileSize.asLongValue()); periodicSizeRotatingFileHandler.setRotateOnBoot(rotationConfig.rotateOnBoot); periodicSizeRotatingFileHandler.setMaxBackupIndex(rotationConfig.maxBackupIndex); handler = periodicSizeRotatingFileHandler; - } else if (rotationConfig.maxFileSize.isPresent()) { + } else { SizeRotatingFileHandler sizeRotatingFileHandler = new SizeRotatingFileHandler( - rotationConfig.maxFileSize.get().asLongValue(), rotationConfig.maxBackupIndex); + rotationConfig.maxFileSize.asLongValue(), rotationConfig.maxBackupIndex); sizeRotatingFileHandler.setRotateOnBoot(rotationConfig.rotateOnBoot); handler = sizeRotatingFileHandler; - } else if (rotationConfig.fileSuffix.isPresent()) { - PeriodicRotatingFileHandler periodicRotatingFileHandler = new PeriodicRotatingFileHandler(); - periodicRotatingFileHandler.setSuffix(rotationConfig.fileSuffix.get()); - handler = periodicRotatingFileHandler; } final PatternFormatter formatter = new PatternFormatter(config.format); diff --git a/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/logging/CategoryConfiguredHandlerTest.java b/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/logging/CategoryConfiguredHandlerTest.java index 915db742c6c56..040b517e224e2 100644 --- a/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/logging/CategoryConfiguredHandlerTest.java +++ b/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/logging/CategoryConfiguredHandlerTest.java @@ -3,11 +3,15 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.Arrays; -import java.util.logging.*; +import java.util.logging.Formatter; +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.LogManager; +import java.util.logging.Logger; import org.jboss.logmanager.formatters.PatternFormatter; import org.jboss.logmanager.handlers.ConsoleHandler; -import org.jboss.logmanager.handlers.FileHandler; +import org.jboss.logmanager.handlers.SizeRotatingFileHandler; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -39,7 +43,7 @@ public void consoleOutputTest() { Logger categoryLogger = logManager.getLogger("io.quarkus.category"); assertThat(categoryLogger).isNotNull(); assertThat(categoryLogger.getHandlers()).hasSize(2).extracting("class").containsExactlyInAnyOrder(ConsoleHandler.class, - FileHandler.class); + SizeRotatingFileHandler.class); Logger otherCategoryLogger = logManager.getLogger("io.quarkus.othercategory"); assertThat(otherCategoryLogger).isNotNull();