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

add option to disable deflate #20

Merged
merged 5 commits into from
Dec 2, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 9 additions & 2 deletions graylog.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var graylog = function graylog(config) {
this.client = null;
this.hostname = config.hostname || require('os').hostname();
this.facility = config.facility || 'Node.js';
this.deflate = config.deflate;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we force this to a boolean here? Perhaps this.deflate = config.delate !== false; or something? Then the code below doesn't have to do an explicit check against false and the default behavior is defined here instead of on-send.


this._unsentMessages = 0;
this._unsentChunks = 0;
Expand Down Expand Up @@ -164,7 +165,7 @@ graylog.prototype._log = function log(short_message, full_message, additionalFie
// Compression
payload = new Buffer(JSON.stringify(message));

zlib.deflate(payload, function (err, buffer) {
function sendPayload(err, buffer) {
if (err) {
that._unsentMessages -= 1;
return that.emitError(err);
Expand Down Expand Up @@ -235,7 +236,13 @@ graylog.prototype._log = function log(short_message, full_message, additionalFie

send();
});
});
}

if (this.deflate === false) { // default to true
sendPayload(null, payload);
} else {
zlib.deflate(payload, sendPayload);
}
};

graylog.prototype.send = function (chunk, server, cb) {
Expand Down
13 changes: 13 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ client.log('ParametersTest - Short message and full message', 'Full message');
client.log('ParametersTest - Short Message with full message and json', 'Full message', {cool: 'beans'});
console.log('');

console.log('---------------------------------------------');
console.log('Sending without deflate');
console.log('---------------------------------------------');
client.deflate = true;
for (var i = 4; i <= 64; i *= 2) {
file = './data/' + i + '.dat';
data = fs.readFileSync(file);
console.log('sending', file);
client.critical('Test 4 ' + file, data.toString(), {datafile: i + '.dat'});
}
delete client.deflate;
console.log('');

client.close(function () {
console.log('Insertion complete. Please check', 'http://' + servers[0].host + ':3000', 'and verify that insertion was successfull');
console.log('');
Expand Down