Skip to content

Commit

Permalink
Logging - set default value for quarkus.log.file.rotation.max-file-size
Browse files Browse the repository at this point in the history
- also change the default value for
quarkus.log.file.rotation.max-backup-index
  • Loading branch information
mkouba committed Apr 26, 2022
1 parent 43afda6 commit 4bd700a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ObjectStore
docker/distroless/bazel-*
/.apt_generated_tests/
quarkus.log
quarkus.log*
replay_*.logß
nbactions.xml
nb-configuration.xml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MemorySize> maxFileSize;
@ConfigItem(defaultValue = "10M")
MemorySize maxFileSize;

/**
* The maximum number of backups to keep.
*/
@ConfigItem(defaultValue = "1")
@ConfigItem(defaultValue = "5")
int maxBackupIndex;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 4bd700a

Please sign in to comment.