Skip to content

Commit de51d08

Browse files
authored
Merge pull request #48479 from mabartos/QKS-48036
Default value for Syslog counting framing
2 parents 4cdddc4 + f2e530c commit de51d08

File tree

4 files changed

+51
-4
lines changed

4 files changed

+51
-4
lines changed

core/runtime/src/main/java/io/quarkus/runtime/logging/LogRuntimeConfig.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,8 @@ interface SyslogConfig {
372372
/**
373373
* If enabled, the message being sent is prefixed with the size of the message
374374
*/
375-
@WithDefault("false")
376-
boolean useCountingFraming();
375+
@WithDefault("protocol-dependent")
376+
CountingFraming useCountingFraming();
377377

378378
/**
379379
* Set to {@code true} to truncate the message if it exceeds maximum length
@@ -420,6 +420,20 @@ interface SyslogConfig {
420420
* Syslog async logging config
421421
*/
422422
AsyncConfig async();
423+
424+
/**
425+
* Syslog counting framing type used for smarter handling of counting framing value.
426+
* <p>
427+
* If {@link CountingFraming#PROTOCOL_DEPENDENT} is used, the counting framing will be {@code true}, when the
428+
* {@link Protocol#TCP} or {@link Protocol#SSL_TCP} is used. Otherwise {@code false}.
429+
* <p>
430+
* More information in <a href="http://tools.ietf.org/html/rfc6587#section-3.4.1">http://tools.ietf.org/html/rfc6587</a>
431+
*/
432+
enum CountingFraming {
433+
TRUE,
434+
FALSE,
435+
PROTOCOL_DEPENDENT
436+
}
423437
}
424438

425439
interface SocketConfig {

core/runtime/src/main/java/io/quarkus/runtime/logging/LoggingSetupRecorder.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,12 @@ private static Handler configureSyslogHandler(final LogRuntimeConfig.SyslogConfi
745745
handler.setProtocol(config.protocol());
746746
handler.setBlockOnReconnect(config.blockOnReconnect());
747747
handler.setTruncate(config.truncate());
748-
handler.setUseCountingFraming(config.useCountingFraming());
748+
handler.setUseCountingFraming(switch (config.useCountingFraming()) {
749+
case PROTOCOL_DEPENDENT ->
750+
config.protocol() == SyslogHandler.Protocol.TCP || config.protocol() == SyslogHandler.Protocol.SSL_TCP;
751+
case TRUE -> true;
752+
case FALSE -> false;
753+
});
749754
handler.setLevel(config.level());
750755
if (config.maxLength().isPresent()) {
751756
BigInteger maxLen = config.maxLength().get().asBigInteger();
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package io.quarkus.logging;
2+
3+
import static io.quarkus.logging.LoggingTestsHelper.getHandler;
4+
import static org.assertj.core.api.Assertions.assertThat;
5+
6+
import org.jboss.logmanager.handlers.SyslogHandler;
7+
import org.junit.jupiter.api.Test;
8+
import org.junit.jupiter.api.extension.RegisterExtension;
9+
10+
import io.quarkus.test.QuarkusUnitTest;
11+
12+
public class SyslogCountingFramingTest {
13+
14+
@RegisterExtension
15+
static final QuarkusUnitTest config = new QuarkusUnitTest()
16+
.withConfigurationResource("application-syslog-output.properties")
17+
.overrideConfigKey("quarkus.log.syslog.protocol", "UDP")
18+
.withApplicationRoot((jar) -> jar.addClass(LoggingTestsHelper.class));
19+
20+
@Test
21+
public void syslogOutputTest() {
22+
SyslogHandler syslogHandler = (SyslogHandler) getHandler(SyslogHandler.class);
23+
24+
assertThat(syslogHandler.getProtocol()).isEqualTo(SyslogHandler.Protocol.UDP);
25+
// counting framing is default 'protocol_dependent', and for UDP the counting framing is off
26+
assertThat(syslogHandler.isUseCountingFraming()).isEqualTo(false);
27+
}
28+
}

integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/logging/SyslogHandlerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void syslogOutputTest() {
4242
assertThat(syslogHandler.getFacility()).isEqualTo(SyslogHandler.Facility.USER_LEVEL);
4343
assertThat(syslogHandler.getSyslogType()).isEqualTo(SyslogHandler.SyslogType.RFC5424);
4444
assertThat(syslogHandler.getProtocol()).isEqualTo(SyslogHandler.Protocol.TCP);
45-
assertThat(syslogHandler.isUseCountingFraming()).isEqualTo(false);
45+
assertThat(syslogHandler.isUseCountingFraming()).isEqualTo(true);
4646
assertThat(syslogHandler.isTruncate()).isEqualTo(true);
4747
assertThat(syslogHandler.isBlockOnReconnect()).isEqualTo(false);
4848
}

0 commit comments

Comments
 (0)