Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extension logging-gelf: Adding missing GELF MDC Config #37943

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,27 @@ public class GelfConfig {
@ConfigItem
public boolean includeFullMdc;

/**
* Send additional fields whose values are obtained from MDC. Name of the Fields are comma-separated. Example:
* mdcFields=Application,Version,SomeOtherFieldName
*/
@ConfigItem()
public Optional<String> mdcFields;

/**
* Dynamic MDC Fields allows you to extract MDC values based on one or more regular expressions. Multiple regexes are
* comma-separated. The name of the MDC entry is used as GELF field name.
*/
@ConfigItem
public Optional<String> dynamicMdcFields;

/**
* Pattern-based type specification for additional and MDC fields. Key-value pairs are comma-separated. Example:
* my_field.*=String,business\..*\.field=double
*/
@ConfigItem
public Optional<String> dynamicMdcFieldTypes;

/**
* Maximum message size (in bytes).
* If the message size is exceeded, the appender will submit the message in multiple chunks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public RuntimeValue<Optional<Handler>> initializeHandler(final GelfConfig config
handler.setFilterStackTrace(config.filterStackTrace);
handler.setTimestampPattern(config.timestampPattern);
handler.setIncludeFullMdc(config.includeFullMdc);
handler.setDynamicMdcFields(config.dynamicMdcFields.orElse(null));
handler.setMdcFields(config.mdcFields.orElse(null));
handler.setDynamicMdcFieldTypes(config.dynamicMdcFieldTypes.orElse(null));
handler.setHost(config.host);
handler.setPort(config.port);
handler.setLevel(config.level);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import jakarta.ws.rs.Path;

import org.jboss.logging.Logger;
import org.jboss.logging.MDC;

/**
* This endpoint allow to test central logging solution by generating a log event when
Expand All @@ -33,6 +34,8 @@ public class GelfLogHandlerResource {

@GET
public void log() {
MDC.put("field3", 99);
MDC.put("field4", 98);
LOG.info("Some useful log message");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ quarkus.log.handler.gelf.facility=custom
quarkus.log.handler.gelf.additional-field.field1.value=value
quarkus.log.handler.gelf.additional-field.field1.type=String
quarkus.log.handler.gelf.additional-field.field2.value=666
quarkus.log.handler.gelf.additional-field.field2.type=long
quarkus.log.handler.gelf.additional-field.field2.type=long
quarkus.log.handler.gelf.include-full-mdc=true
quarkus.log.handler.gelf.dynamic-mdc-field-types=field3=String
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public void test() {
assertEquals(200, response.statusCode());
assertNotNull(response.body().path("hits.hits[0]._source"));
assertEquals("Some useful log message", response.body().path("hits.hits[0]._source.message"));
assertEquals(Integer.valueOf(98), response.body().path("hits.hits[0]._source.field4"));
assertEquals("99", response.body().path("hits.hits[0]._source.field3"));
});
}
}