Skip to content
This repository has been archived by the owner on Jun 29, 2023. It is now read-only.

Commit

Permalink
Add version field to GelfMessage #260
Browse files Browse the repository at this point in the history
* Add version field

Add version field for GELF versions 1.1 and up as specified here:
https://docs.graylog.org/en/latest/pages/gelf.html
> version string (UTF-8)
> GELF spec version – “1.1”; MUST be set by client library.

* Unit test

added unit test for version field
  • Loading branch information
normakm authored Mar 1, 2021
1 parent 3b74daf commit 2e231c7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class GelfMessage {
public static final String FIELD_TIMESTAMP = "timestamp";
public static final String FIELD_LEVEL = "level";
public static final String FIELD_FACILITY = "facility";
public static final String FIELD_VERSION = "version";
public static final String ID_NAME = "id";

/**
Expand Down Expand Up @@ -154,6 +155,10 @@ protected void toJson(OutputAccessor out, String additionalFieldPrefix) {

boolean hasFields = writeIfNotEmpty(out, false, FIELD_HOST, getHost());

if (!isEmpty(version) && !GELF_VERSION_1_0.equals(version)) {
hasFields = writeIfNotEmpty(out, hasFields, FIELD_VERSION, version);
}

if (!isEmpty(shortMessage)) {
hasFields = writeIfNotEmpty(out, hasFields, FIELD_SHORT_MESSAGE, getShortMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ void testGelf_v1_1() {
assertThat(gelfMessage.getVersion()).isEqualTo(GelfMessage.GELF_VERSION_1_1);
assertThat(gelfMessage.toJson()).contains("\"level\":6");
assertThat(gelfMessage.toJson()).contains("\"timestamp\":123.456");
assertThat(gelfMessage.toJson()).contains("\"version\":\"1.1\"");

}

Expand Down

0 comments on commit 2e231c7

Please sign in to comment.