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") }; };