Unable to set '--log-syslog-max-length' property (#36253)

Closes #35386

Signed-off-by: Martin Bartoš <mabartos@redhat.com>
This commit is contained in:
Martin Bartoš
2025-01-13 17:48:23 +01:00
committed by GitHub
parent ed16c89b7d
commit 71f515feb9
3 changed files with 28 additions and 1 deletions

View File

@@ -173,7 +173,7 @@ public class LoggingOptions {
.defaultValue(SyslogHandler.SyslogType.RFC5424.toString().toLowerCase())
.build();
public static final Option<MemorySize> LOG_SYSLOG_MAX_LENGTH = new OptionBuilder<>("log-syslog-max-length", MemorySize.class)
public static final Option<String> LOG_SYSLOG_MAX_LENGTH = new OptionBuilder<>("log-syslog-max-length", String.class)
.category(OptionCategory.LOGGING)
// based on the 'quarkus.log.syslog.max-length' property
.description("Set the maximum length, in bytes, of the message allowed to be sent. The length includes the header and the message. " +

View File

@@ -12,6 +12,7 @@ import java.util.function.BiFunction;
import java.util.logging.Level;
import java.util.stream.Stream;
import io.quarkus.runtime.configuration.MemorySizeConverter;
import org.jboss.logmanager.LogContext;
import org.keycloak.config.LoggingOptions;
import org.keycloak.config.Option;
@@ -135,6 +136,7 @@ public final class LoggingPropertyMappers {
fromOption(LoggingOptions.LOG_SYSLOG_MAX_LENGTH)
.isEnabled(LoggingPropertyMappers::isSyslogEnabled, SYSLOG_ENABLED_MSG)
.to("quarkus.log.syslog.max-length")
.validator(LoggingPropertyMappers::validateSyslogMaxLength)
.paramLabel("max-length")
.build(),
fromOption(LoggingOptions.LOG_SYSLOG_PROTOCOL)
@@ -258,4 +260,13 @@ public final class LoggingPropertyMappers {
return Optional.of(LoggingOptions.DEFAULT_LOG_TRACING_FORMAT);
}
private static void validateSyslogMaxLength(String value) {
var converter = new MemorySizeConverter();
try {
converter.convert(value);
} catch (IllegalArgumentException e) {
throw new PropertyException(String.format("Invalid value for option '--log-syslog-max-length': %s", e.getMessage()));
}
}
}

View File

@@ -19,6 +19,7 @@ package org.keycloak.quarkus.runtime.cli;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
@@ -205,4 +206,19 @@ public class PicocliTest extends AbstractConfigurationTest {
"Option: '--db postgres' is not expected to contain whitespace, please remove any unnecessary quoting/escaping"));
}
@Test
public void syslogMaxLengthMemorySize() {
NonRunningPicocli nonRunningPicocli = pseudoLaunch("start-dev", "--log=syslog", "--log-syslog-max-length=60k");
assertEquals(CommandLine.ExitCode.OK, nonRunningPicocli.exitCode);
assertEquals("60k", nonRunningPicocli.config.getConfigValue("quarkus.log.syslog.max-length").getValue());
nonRunningPicocli = pseudoLaunch("start-dev", "--log=syslog");
assertEquals(CommandLine.ExitCode.OK, nonRunningPicocli.exitCode);
assertThat(nonRunningPicocli.config.getConfigValue("quarkus.log.syslog.max-length").getValue(), nullValue());
nonRunningPicocli = pseudoLaunch("start-dev", "--log=syslog", "--log-syslog-max-length=wrong");
assertEquals(CommandLine.ExitCode.USAGE, nonRunningPicocli.exitCode);
assertThat(nonRunningPicocli.getErrString(), containsString(
"Invalid value for option '--log-syslog-max-length': value wrong not in correct format (regular expression): [0-9]+[BbKkMmGgTtPpEeZzYy]?"));
}
}