Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging - set default value for quarkus.log.file.rotation.max-file-size #25072

Merged
merged 1 commit into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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