From 0e33c10eb2bb03bd74e418ae511ce6f651e173bb Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Tue, 9 Apr 2024 10:22:46 +0300 Subject: [PATCH] Add maxLength configuration option to SysLog Closes: #39944 --- .../runtime/logging/LoggingSetupRecorder.java | 19 +++++++++++++++++++ .../quarkus/runtime/logging/SyslogConfig.java | 10 ++++++++++ 2 files changed, 29 insertions(+) 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 6b37b15685d7d..6108893f04013 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 @@ -6,6 +6,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.UnsupportedEncodingException; +import java.math.BigInteger; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -687,6 +688,24 @@ private static Handler configureSyslogHandler(final SyslogConfig config, final E handler.setTruncate(config.truncate); handler.setUseCountingFraming(config.useCountingFraming); handler.setLevel(config.level); + if (config.maxLength.isPresent()) { + BigInteger maxLen = config.maxLength.get().asBigInteger(); + if (maxLen.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) { + errorManager.error( + "Using 2GB as the value of maxLength for SyslogHandler as it is the maximum allowed value", null, + ErrorManager.GENERIC_FAILURE); + maxLen = BigInteger.valueOf(Integer.MAX_VALUE); + } else { + BigInteger minimumAllowedMaxLength = BigInteger.valueOf(128); + if (maxLen.compareTo(minimumAllowedMaxLength) < 0) { + errorManager.error( + "Using 128 as the value of maxLength for SyslogHandler as using a smaller value is not allowed", + null, ErrorManager.GENERIC_FAILURE); + maxLen = minimumAllowedMaxLength; + } + } + handler.setMaxLength(maxLen.intValue()); + } Formatter formatter = null; boolean formatterWarning = false; diff --git a/core/runtime/src/main/java/io/quarkus/runtime/logging/SyslogConfig.java b/core/runtime/src/main/java/io/quarkus/runtime/logging/SyslogConfig.java index 0411d345fdcc3..767a0a5b92c85 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/logging/SyslogConfig.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/logging/SyslogConfig.java @@ -10,6 +10,7 @@ import io.quarkus.runtime.annotations.ConfigGroup; import io.quarkus.runtime.annotations.ConfigItem; +import io.quarkus.runtime.configuration.MemorySize; @ConfigGroup public class SyslogConfig { @@ -95,6 +96,15 @@ public class SyslogConfig { @ConfigItem Optional filter; + /** + * The maximum length, in bytes, of the message allowed to be sent. The length includes the header and the message. + *

+ * If not set, the default value is {@code 2048} when {@code sys-log-type} is {@code rfc5424} (which is the default) + * and {@code 1024} when {@code sys-log-type} is {@code rfc3164} + */ + @ConfigItem + Optional maxLength; + /** * Syslog async logging config */