Skip to content

Commit

Permalink
Merge pull request #25674 from geoand/#25643
Browse files Browse the repository at this point in the history
Add config option for skipping hostname resolution in Gelf logging
  • Loading branch information
geoand authored May 19, 2022
2 parents 3b97874 + 0601d58 commit aa8ba94
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -117,4 +118,17 @@ public class GelfConfig {
*/
@ConfigItem(defaultValue = "true")
public boolean includeLocation;

/**
* Origin hostname
*/
@ConfigItem
public Optional<String> 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;
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,7 +17,18 @@ public RuntimeValue<Optional<Handler>> 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);
Expand All @@ -32,6 +45,9 @@ public RuntimeValue<Optional<Handler>> 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()) {
Expand Down

0 comments on commit aa8ba94

Please sign in to comment.