manually merged TooTallNate's pull request #62

This commit is contained in:
Gareth Jones 2012-05-29 16:49:12 +10:00
parent 754ac2c5ac
commit 38a89dcf3d
3 changed files with 20 additions and 16 deletions

View File

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

View File

@ -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",

View File

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