Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

Modified LogglyBatchAppender to Insert Newline Characters (0x0A) Between Each Log Event #21

Closed
wants to merge 10 commits into from

Conversation

MusikPolice
Copy link

This patch addresses #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 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.

…ality to DiscardingRollingOutputStream along with unit tests for all new methods
… stream prior to each new log event if the stream is non-empty and does not currently end with a newline. This is necessary when shipping JSON events with the ch.qos.logback.contrib.jackson.JacksonJsonFormatter, as it does not append newline characters, but loggly expects them to break individual batch members into separate events.
tony19 added a commit that referenced this pull request Mar 6, 2014
This fixes a problem where every batch sent to loggly was seen as
a single log event instead of the individual events within the
batch.
@tony19
Copy link
Contributor

tony19 commented Mar 6, 2014

Fixed in d51377c

@tony19 tony19 closed this Mar 6, 2014
tony19 added a commit that referenced this pull request Mar 6, 2014
tony19 added a commit that referenced this pull request Mar 6, 2014
tony19 added a commit that referenced this pull request Mar 6, 2014
Make sure messages end with new-line char to delimit individual
log events within the batch sent to loggly.

Fixes #21
@tony19
Copy link
Contributor

tony19 commented Mar 6, 2014

Re-implemented in simpler way: 56de824

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants