Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge remote branch 'upstream/master'

Conflicts:
	pom.xml
	src/test/java/org/graylog2/log/GelfAppenderTest.java
  • Loading branch information...
commit 68126525ae54d621736b7cba1bc079f2d936dbea 2 parents 60ac209 + 22653f1
@ssundell authored
View
2  pom.xml
@@ -6,7 +6,7 @@
<groupId>org.graylog2</groupId>
<artifactId>gelfj</artifactId>
- <version>0.7.1-mt-SNAPSHOT</version>
+ <version>0.8.0-mt-SNAPSHOT</version>
<packaging>jar</packaging>
<name>gelfj</name>
View
10 src/main/java/org/graylog2/log/GelfAppender.java
@@ -128,7 +128,12 @@ protected void append(LoggingEvent event) {
String lineNumber = locationInformation.getLineNumber();
String renderedMessage = event.getRenderedMessage();
- String shortMessage = "";
+ String shortMessage;
+
+ if(renderedMessage == null) {
+ renderedMessage = "";
+ }
+
if (renderedMessage.length() > MAX_SHORT_MESSAGE_LENGTH) {
shortMessage = renderedMessage.substring(0, MAX_SHORT_MESSAGE_LENGTH - 1);
} else {
@@ -141,7 +146,8 @@ protected void append(LoggingEvent event) {
renderedMessage += "\n\r" + extractStacktrace(throwableInformation);
}
}
- GelfMessage gelfMessage = new GelfMessage(shortMessage, renderedMessage, timeStamp, level.getSyslogEquivalent() + "", lineNumber, file);
+ GelfMessage gelfMessage = new GelfMessage(shortMessage, renderedMessage, timeStamp,
+ String.valueOf(level.getSyslogEquivalent()), lineNumber, file);
if (getOriginHost() != null) {
gelfMessage.setHost(getOriginHost());
View
26 src/test/java/org/graylog2/log/GelfAppenderTest.java
@@ -8,6 +8,7 @@
import org.apache.log4j.spi.LoggingEvent;
import org.graylog2.GelfMessage;
import org.graylog2.GelfSender;
+import org.junit.Before;
import org.junit.Test;
import java.net.SocketException;
@@ -18,12 +19,14 @@
*/
public class GelfAppenderTest {
- @Test
- public void ensureHostnameForMessage() throws UnknownHostException, SocketException {
+ private TestGelfSender gelfSender;
+ private GelfAppender gelfAppender;
- final TestGelfSender gelfSender = new TestGelfSender("localhost");
+ @Before
+ public void setUp() throws UnknownHostException, SocketException {
+ gelfSender = new TestGelfSender("localhost");
- GelfAppender gelfAppender = new GelfAppender() {
+ gelfAppender = new GelfAppender() {
@Override
public GelfSender getGelfSender() {
@@ -35,11 +38,26 @@ public void append(LoggingEvent event) {
super.append(event);
}
};
+ }
+
+ @Test
+ public void ensureHostnameForMessage() {
LoggingEvent event = new LoggingEvent("a.b.c.DasClass", Category.getInstance(this.getClass()), 123L, Priority.INFO, "Das Auto",
new RuntimeException("LOL"));
gelfAppender.append(event);
+ assertThat("Message short message", gelfSender.getLastMessage().getShortMessage(), notNullValue());
+ assertThat("Message full message", gelfSender.getLastMessage().getFullMessage(), notNullValue());
+ }
+
+ @Test
+ public void handleNullInAppend() throws UnknownHostException, SocketException {
+
+ LoggingEvent event = new LoggingEvent("a.b.c.DasClass", Category.getInstance(this.getClass()), 123L, Priority.INFO, null,
+ new RuntimeException("LOL"));
+ gelfAppender.append(event);
+
assertThat("Message hostname", gelfSender.getLastMessage().getHost(), notNullValue());
gelfAppender.setOriginHost("example.com");
Please sign in to comment.
Something went wrong with that request. Please try again.