diff --git a/extensions/logging-gelf/runtime/src/main/java/io/quarkus/logging/gelf/GelfConfig.java b/extensions/logging-gelf/runtime/src/main/java/io/quarkus/logging/gelf/GelfConfig.java index d4e6deabf313e..e67d288e8d14b 100644 --- a/extensions/logging-gelf/runtime/src/main/java/io/quarkus/logging/gelf/GelfConfig.java +++ b/extensions/logging-gelf/runtime/src/main/java/io/quarkus/logging/gelf/GelfConfig.java @@ -1,6 +1,7 @@ package io.quarkus.logging.gelf; import java.util.Map; +import java.util.Optional; import java.util.logging.Level; import io.quarkus.runtime.annotations.ConfigDocMapKey; @@ -117,4 +118,17 @@ public class GelfConfig { */ @ConfigItem(defaultValue = "true") public boolean includeLocation; + + /** + * Origin hostname + */ + @ConfigItem + public Optional originHost; + + /** + * Bypass hostname resolution. If you didn't set the {@code originHost} property, and resolution is disabled, the value + * “unknown” will be used as hostname + */ + @ConfigItem + public boolean skipHostnameResolution; } diff --git a/extensions/logging-gelf/runtime/src/main/java/io/quarkus/logging/gelf/GelfLogHandlerRecorder.java b/extensions/logging-gelf/runtime/src/main/java/io/quarkus/logging/gelf/GelfLogHandlerRecorder.java index 66947c6d26886..6000d36215459 100644 --- a/extensions/logging-gelf/runtime/src/main/java/io/quarkus/logging/gelf/GelfLogHandlerRecorder.java +++ b/extensions/logging-gelf/runtime/src/main/java/io/quarkus/logging/gelf/GelfLogHandlerRecorder.java @@ -1,5 +1,7 @@ package io.quarkus.logging.gelf; +import static biz.paluch.logging.RuntimeContainerProperties.PROPERTY_LOGSTASH_GELF_SKIP_HOSTNAME_RESOLUTION; + import java.util.Map; import java.util.Optional; import java.util.logging.Handler; @@ -15,7 +17,18 @@ public RuntimeValue> initializeHandler(final GelfConfig config return new RuntimeValue<>(Optional.empty()); } + String previousSkipHostnameResolution = null; + if (config.skipHostnameResolution) { + previousSkipHostnameResolution = System.setProperty(PROPERTY_LOGSTASH_GELF_SKIP_HOSTNAME_RESOLUTION, "true"); + } final JBoss7GelfLogHandler handler = new JBoss7GelfLogHandler(); + if (config.skipHostnameResolution) { + if (previousSkipHostnameResolution == null) { + System.clearProperty(PROPERTY_LOGSTASH_GELF_SKIP_HOSTNAME_RESOLUTION); + } else { + System.setProperty(PROPERTY_LOGSTASH_GELF_SKIP_HOSTNAME_RESOLUTION, previousSkipHostnameResolution); + } + } handler.setVersion(config.version); handler.setFacility(config.facility); String extractStackTrace = String.valueOf(config.extractStackTrace); @@ -32,6 +45,9 @@ public RuntimeValue> initializeHandler(final GelfConfig config handler.setMaximumMessageSize(config.maximumMessageSize); handler.setIncludeLocation(config.includeLocation); handler.setIncludeLogMessageParameters(config.includeLogMessageParameters); + if (config.originHost.isPresent()) { + handler.setOriginHost(config.originHost.get()); + } // handle additional fields if (!config.additionalField.isEmpty()) {