Skip to content

Commit f91519f

Browse files
committed
add test for blank short_message #82
1 parent 70a4906 commit f91519f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/test/java/de/siegmar/logbackgelf/GelfEncoderTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.slf4j.MarkerFactory;
4343
import org.slf4j.event.KeyValuePair;
4444

45+
import com.fasterxml.jackson.core.JsonProcessingException;
4546
import com.fasterxml.jackson.databind.JsonNode;
4647
import com.fasterxml.jackson.databind.ObjectMapper;
4748
import com.google.common.collect.ImmutableMap;
@@ -478,6 +479,21 @@ void originHostDefaultToLocalHostNameIfEmpty(final String configuredHostname) th
478479
assertEquals(localhost, encoder.getOriginHost());
479480
}
480481

482+
@Test
483+
void blankShortmessage() throws JsonProcessingException {
484+
encoder.start();
485+
486+
final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
487+
final Logger logger = lc.getLogger(LOGGER_NAME);
488+
489+
final LoggingEvent event = new LoggingEvent(LOGGER_NAME, logger, Level.DEBUG, " \t ", null, new Object[]{1});
490+
final String logMsg = encodeToStr(event);
491+
492+
final ObjectMapper om = new ObjectMapper();
493+
final JsonNode jsonNode = om.readTree(logMsg);
494+
assertEquals("Empty message replaced by logback-gelf", jsonNode.get("short_message").textValue());
495+
}
496+
481497
@Test
482498
void defaultValues() {
483499
assertFalse(encoder.isIncludeRawMessage());

0 commit comments

Comments
 (0)