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

Allow Appenders and Handlers to pass a zero length message to network #96

Merged
merged 1 commit into from Feb 1, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/java/org/graylog2/GelfMessage.java
Expand Up @@ -40,7 +40,7 @@ public GelfMessage(String shortMessage, String fullMessage, long timestamp, Stri
}

public GelfMessage(String shortMessage, String fullMessage, long timestamp, String level, String line, String file) {
this.shortMessage = shortMessage;
this.shortMessage = shortMessage != null ? shortMessage : "null";
this.fullMessage = fullMessage;
this.javaTimestamp = timestamp;
this.level = level;
Expand Down Expand Up @@ -210,7 +210,7 @@ public void setHost(String host) {
}

public String getShortMessage() {
return !isEmpty(shortMessage) ? shortMessage : "<empty>";
return shortMessage;
}

public void setShortMessage(String shortMessage) {
Expand Down Expand Up @@ -292,7 +292,7 @@ public boolean isValid() {
}

private boolean isShortOrFullMessagesExists() {
return !isEmpty(shortMessage) || !isEmpty(fullMessage);
return shortMessage != null || fullMessage != null;
}

public boolean isEmpty(String str) {
Expand Down
16 changes: 14 additions & 2 deletions src/test/java/org/graylog2/GelfMessageTest.java
Expand Up @@ -88,16 +88,28 @@ public void testEmptyShortMessage() {
message.setVersion("0.0");

assertThat("Message with empty short message is Valid", message.isValid(), is(true));
assertThat("Short message is set to <empty> when null", message.getShortMessage(), is("<empty>"));
assertThat("Short message is set to 'null' when null", message.getShortMessage(), is("null"));

message.setFullMessage(null);
assertThat("Not valid when not full message set nor short message set", message.isValid(), is(false));
assertThat("An empty message is valid (neither full nor short message set)", message.isValid(), is(true));

message.setShortMessage("Hamburg");
message.setFullMessage(null);
assertThat("Valid when short message is set", message.isValid(), is(true));
}

@Test
public void testZeroLengthMessage() {
GelfMessage message = new GelfMessage("", "", 1L, "1");

message.setHost("localhost");
message.setVersion("0.0");
assertThat("Message with a zero length short message is Valid",
message.isValid(), is(true));
assertThat("Short message is set to an empty string when zero length",
message.getShortMessage(), is(""));
}

@Test
public void testInvalidLevelMessage() {
GelfMessage message = new GelfMessage("Short", "Long", 1L, "WARNING");
Expand Down