qos-ch/logback-extensions — pull request #21 by MusikPolice (2014-02-27 21:49:47+00:00)
Title: Modified LogglyBatchAppender to Insert Newline Characters (0x0A) Between Each Log Event

This patch addresses https://github.com/qos-ch/logback-extensions/issues/17

When using the LogglyBatchAppender with the ch.qos.logback.contrib.json.classic.JsonLayout layout class, new line characters (0x0A) are not inserted into the buffer between each JSON object. This causes Loggly to interpret the entire batch request as a single log event, instead of as n distinct events.

My patch inserts a newline character prior to each log event if the stream is currently non-empty and does not have a newline character in the last position. This means that it will be backward compatible with other layout managers that add the newline character automatically, but will fix the issues with the JSON layout manager.

The new methods that were added to DiscardingRollingOutputStream have full test coverage, and I have confirmed that LogglyBatchAppender correctly inserts newlines by using [Charles](http://www.charlesproxy.com/) to sniff traffic during ad-hoc testing against a live Loggly instance. It should be possible to add automatic unit testing for this file once the @Ignore annotation is removed from the existing test cases.

A Note about Diffs: The diff of the code appears to have replaced every line in each of the two files that I edited - this is probably do to some kind of formatting change. I didn't actually rewrite all of the code.