From 38a89dcf3d3ebef70cc2ac67f451e1948dd52ce3 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Tue, 29 May 2012 16:49:12 +1000 Subject: [PATCH] manually merged TooTallNate's pull request #62 --- lib/appenders/gelf.js | 19 ++++++++++++------- package.json | 3 +-- test/gelfAppender.js | 14 +++++++------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/appenders/gelf.js b/lib/appenders/gelf.js index ebeff38..38a09b6 100644 --- a/lib/appenders/gelf.js +++ b/lib/appenders/gelf.js @@ -1,4 +1,4 @@ -var compress = require('compress-buffer').compress; +var zlib = require('zlib'); var layouts = require('../layouts'); var levels = require('../levels'); var dgram = require('dgram'); @@ -67,12 +67,17 @@ function gelfAppender (layout, host, port, hostname, facility) { return function(loggingEvent) { var message = preparePacket(loggingEvent); - var packet = compress(new Buffer(JSON.stringify(message))); - if (packet.length > 8192) { - util.debug("Message packet length (" + packet.length + ") is larger than 8k. Not sending"); - } else { - sendPacket(packet); - } + zlib.gzip(new Buffer(JSON.stringify(message)), function(err, packet) { + if (err) { + console.error(err.stack); + } else { + if (packet.length > 8192) { + util.debug("Message packet length (" + packet.length + ") is larger than 8k. Not sending"); + } else { + sendPacket(packet); + } + } + }); }; } diff --git a/package.json b/package.json index b20466b..b094ead 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,7 @@ "lib": "lib" }, "dependencies": { - "async": "0.1.15", - "compress-buffer": "0.5.1" + "async": "0.1.15" }, "devDependencies": { "vows": "0.6.2", diff --git a/test/gelfAppender.js b/test/gelfAppender.js index 713f146..3273212 100644 --- a/test/gelfAppender.js +++ b/test/gelfAppender.js @@ -23,20 +23,20 @@ var vows = require('vows') return this.socket; } } - , fakeCompressBuffer = { - compress: function(objectToCompress) { - fakeCompressBuffer.uncompressed = objectToCompress; + , fakeZlib = { + gzip: function(objectToCompress, callback) { + fakeZlib.uncompressed = objectToCompress; if (compressedLength) { - return { length: compressedLength }; + callback(null, { length: compressedLength }); } else { - return "I've been compressed"; + callback(null, "I've been compressed"); } } } , appender = sandbox.require('../lib/appenders/gelf', { requires: { dgram: fakeDgram, - "compress-buffer": fakeCompressBuffer + zlib: fakeZlib } }); @@ -44,7 +44,7 @@ var vows = require('vows') log4js.addAppender(appender.configure(options || {}), category || "gelf-test"); return { dgram: fakeDgram, - compress: fakeCompressBuffer, + compress: fakeZlib, logger: log4js.getLogger(category || "gelf-test") }; };