Skip to content

Commit

Permalink
Merge pull request #37943 from donkon/gelf-missing-mdc-config
Browse files Browse the repository at this point in the history
Extension logging-gelf: Adding missing GELF MDC Config
  • Loading branch information
loicmathieu authored Jan 15, 2024
2 parents 28144e0 + badc901 commit 15bf7c1
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
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"));
});
}
}

0 comments on commit 15bf7c1

Please sign in to comment.