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 58ed4b16893be..40f7ec711acde 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
@@ -74,6 +74,8 @@ public static class RotationConfig {
/**
* Indicates whether to rotate log files on server initialization.
+ *
+ * You need to either set a {@code max-file-size} or configure a {@code file-suffix} for it to work.
*/
@ConfigItem(defaultValue = "true")
boolean rotateOnBoot;
diff --git a/core/runtime/src/main/java/io/quarkus/runtime/logging/LogConfig.java b/core/runtime/src/main/java/io/quarkus/runtime/logging/LogConfig.java
index ebc5841e94109..1e5a257ee0d42 100644
--- a/core/runtime/src/main/java/io/quarkus/runtime/logging/LogConfig.java
+++ b/core/runtime/src/main/java/io/quarkus/runtime/logging/LogConfig.java
@@ -36,6 +36,30 @@ public final class LogConfig {
@ConfigItem(defaultValue = "INFO")
public Level minLevel;
+ /**
+ * Console logging.
+ *
+ * Console logging is enabled by default.
+ */
+ @ConfigDocSection
+ public ConsoleConfig console;
+
+ /**
+ * File logging.
+ *
+ * Logging to a file is also supported but not enabled by default.
+ */
+ @ConfigDocSection
+ public FileConfig file;
+
+ /**
+ * Syslog logging.
+ *
+ * Logging to a syslog is also supported but not enabled by default.
+ */
+ @ConfigDocSection
+ public SyslogConfig syslog;
+
/**
* Logging categories.
*
@@ -74,30 +98,6 @@ public final class LogConfig {
@ConfigDocSection
public Map syslogHandlers;
- /**
- * Console logging.
- *
- * Console logging is enabled by default.
- */
- @ConfigDocSection
- public ConsoleConfig console;
-
- /**
- * File logging.
- *
- * Logging to a file is also supported but not enabled by default.
- */
- @ConfigDocSection
- public FileConfig file;
-
- /**
- * Syslog logging.
- *
- * Logging to a syslog is also supported but not enabled by default.
- */
- @ConfigDocSection
- public SyslogConfig syslog;
-
/**
* Log cleanup filters - internal use.
*/
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 4682cf3d094b6..d2f959e3a3c49 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
@@ -284,10 +284,12 @@ private static Handler configureFileHandler(final FileConfig config, final Error
final List filterElements) {
FileHandler handler = new FileHandler();
FileConfig.RotationConfig rotationConfig = config.rotation;
- if (rotationConfig.maxFileSize.isPresent() && rotationConfig.fileSuffix.isPresent()) {
+ if ((rotationConfig.maxFileSize.isPresent() || rotationConfig.rotateOnBoot)
+ && rotationConfig.fileSuffix.isPresent()) {
PeriodicSizeRotatingFileHandler periodicSizeRotatingFileHandler = new PeriodicSizeRotatingFileHandler();
periodicSizeRotatingFileHandler.setSuffix(rotationConfig.fileSuffix.get());
- periodicSizeRotatingFileHandler.setRotateSize(rotationConfig.maxFileSize.get().asLongValue());
+ rotationConfig.maxFileSize
+ .ifPresent(memorySize -> periodicSizeRotatingFileHandler.setRotateSize(memorySize.asLongValue()));
periodicSizeRotatingFileHandler.setRotateOnBoot(rotationConfig.rotateOnBoot);
periodicSizeRotatingFileHandler.setMaxBackupIndex(rotationConfig.maxBackupIndex);
handler = periodicSizeRotatingFileHandler;
diff --git a/core/test-extension/deployment/src/main/resources/application-periodic-size-file-log-rotating-rotate-on-boot.properties b/core/test-extension/deployment/src/main/resources/application-periodic-size-file-log-rotating-rotate-on-boot.properties
new file mode 100644
index 0000000000000..f4609582ecd93
--- /dev/null
+++ b/core/test-extension/deployment/src/main/resources/application-periodic-size-file-log-rotating-rotate-on-boot.properties
@@ -0,0 +1,7 @@
+quarkus.log.level=INFO
+quarkus.log.file.enable=true
+quarkus.log.file.level=INFO
+quarkus.log.file.format=%d{HH:mm:ss} %-5p [%c{2.}]] (%t) %s%e%n
+quarkus.log.file.rotation.file-suffix=.yyyy-MM-dd
+quarkus.log.file.rotation.rotate-on-boot=true
+quarkus.root.dsa-key-location=/DSAPublicKey.encoded
diff --git a/core/test-extension/deployment/src/test/java/io/quarkus/logging/LoggingTestsHelper.java b/core/test-extension/deployment/src/test/java/io/quarkus/logging/LoggingTestsHelper.java
index b2d130f214563..b103f2dd1652d 100644
--- a/core/test-extension/deployment/src/test/java/io/quarkus/logging/LoggingTestsHelper.java
+++ b/core/test-extension/deployment/src/test/java/io/quarkus/logging/LoggingTestsHelper.java
@@ -3,12 +3,14 @@
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Arrays;
+import java.util.Optional;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import org.jboss.logmanager.handlers.DelayedHandler;
+import org.junit.jupiter.api.Assertions;
import io.quarkus.bootstrap.logging.InitialConfigurator;
@@ -22,9 +24,10 @@ public static Handler getHandler(Class clazz) {
assertThat(Logger.getLogger("").getHandlers()).contains(delayedHandler);
assertThat(delayedHandler.getLevel()).isEqualTo(Level.ALL);
- Handler handler = Arrays.stream(delayedHandler.getHandlers()).filter(h -> (clazz.isInstance(h)))
- .findFirst().get();
- assertThat(handler).isNotNull();
- return handler;
+ Optional handler = Arrays.stream(delayedHandler.getHandlers()).filter(h -> (clazz.isInstance(h)))
+ .findFirst();
+ Assertions.assertTrue(handler.isPresent(), () -> String.format("Could not find handler of type %s: %s", clazz,
+ Arrays.asList(delayedHandler.getHandlers())));
+ return handler.get();
}
}
diff --git a/core/test-extension/deployment/src/test/java/io/quarkus/logging/PeriodicSizeRotatingLoggingRotateOnBootTest.java b/core/test-extension/deployment/src/test/java/io/quarkus/logging/PeriodicSizeRotatingLoggingRotateOnBootTest.java
new file mode 100644
index 0000000000000..d5b0e6f82d655
--- /dev/null
+++ b/core/test-extension/deployment/src/test/java/io/quarkus/logging/PeriodicSizeRotatingLoggingRotateOnBootTest.java
@@ -0,0 +1,44 @@
+package io.quarkus.logging;
+
+import static io.quarkus.logging.LoggingTestsHelper.getHandler;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.logging.Formatter;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+
+import org.jboss.logmanager.formatters.PatternFormatter;
+import org.jboss.logmanager.handlers.PeriodicSizeRotatingFileHandler;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import io.quarkus.test.QuarkusUnitTest;
+
+public class PeriodicSizeRotatingLoggingRotateOnBootTest {
+
+ private static final String FILE_NAME = PeriodicSizeRotatingLoggingRotateOnBootTest.class.getSimpleName() + ".log";
+
+ @RegisterExtension
+ static final QuarkusUnitTest config = new QuarkusUnitTest()
+ .withConfigurationResource("application-periodic-size-file-log-rotating-rotate-on-boot.properties")
+ .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
+ .addClass(LoggingTestsHelper.class)
+ .addAsManifestResource("application.properties", "microprofile-config.properties"))
+ .setLogFileName(FILE_NAME);
+
+ @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();
+ }
+}