Merge pull request #56 from arifamirani/master
Fixed tests for gelf appender
This commit is contained in:
commit
2ab6f5fa24
@ -13,7 +13,7 @@ var util = require('util');
|
|||||||
* @param hostname - hostname of the current host (default:os hostname)
|
* @param hostname - hostname of the current host (default:os hostname)
|
||||||
* @param facility - facility to log to (default:nodejs-server)
|
* @param facility - facility to log to (default:nodejs-server)
|
||||||
*/
|
*/
|
||||||
function gelfAppender (layout, host, port, hostname, facility) {
|
function gelfAppender (layout, host, port, hostname, facility, externalClient) {
|
||||||
|
|
||||||
var logEventBuffer = [];
|
var logEventBuffer = [];
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ function gelfAppender (layout, host, port, hostname, facility) {
|
|||||||
facility = facility || 'nodejs-server';
|
facility = facility || 'nodejs-server';
|
||||||
layout = layout || layouts.patternLayout('%m');
|
layout = layout || layouts.patternLayout('%m');
|
||||||
|
|
||||||
var client = dgram.createSocket("udp4");
|
var client = externalClient || dgram.createSocket("udp4");
|
||||||
|
|
||||||
process.on('exit', function() {
|
process.on('exit', function() {
|
||||||
if (client) client.close();
|
if (client) client.close();
|
||||||
@ -90,7 +90,7 @@ function configure(config) {
|
|||||||
if (config.layout) {
|
if (config.layout) {
|
||||||
layout = layouts.layout(config.layout.type, config.layout);
|
layout = layouts.layout(config.layout.type, config.layout);
|
||||||
}
|
}
|
||||||
return gelfAppender(layout, config.host, config.port, config.hostname, config.facility);
|
return gelfAppender(layout, config.host, config.port, config.hostname, config.facility, config.client);
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.name = "gelf";
|
exports.name = "gelf";
|
||||||
|
@ -1,31 +1,30 @@
|
|||||||
var vows = require('vows')
|
var vows = require('vows')
|
||||||
, log4js = require('../lib/log4js')
|
, log4js = require('../lib/log4js')
|
||||||
, assert = require('assert')
|
, assert = require('assert')
|
||||||
, util = require('util')
|
|
||||||
, dgram = require("dgram");
|
, dgram = require("dgram");
|
||||||
|
|
||||||
log4js.configure({ "appenders": [{"type": "gelf"}] }, undefined);
|
var fakeClient = {
|
||||||
|
packetLength: 0,
|
||||||
|
close: function() {
|
||||||
|
},
|
||||||
|
send: function(pkt, offset, pktLength, port, host) {
|
||||||
|
this.packetLength = pktLength;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
log4js.configure({ "appenders": [{"type": "gelf", "client": fakeClient}] }, undefined);
|
||||||
|
|
||||||
vows.describe('log4js gelfAppender').addBatch({
|
vows.describe('log4js gelfAppender').addBatch({
|
||||||
|
|
||||||
'with default gelfAppender settings': {
|
'with default gelfAppender settings': {
|
||||||
topic: function() {
|
topic: function() {
|
||||||
var logger = log4js.getLogger();
|
var logger = log4js.getLogger();
|
||||||
|
var self = this;
|
||||||
//Start local dgram server to act as GELF server
|
logger.info('Fake log message');
|
||||||
var server = dgram.createSocket("udp4");
|
callback();
|
||||||
//Assert as soon as message arrives
|
|
||||||
server.on("message", this.callback);
|
|
||||||
//Send a fake message as soon as server is ready
|
|
||||||
server.on("listening", function () {
|
|
||||||
logger.info("This should be a packet of size 161 bytes at the server");
|
|
||||||
});
|
|
||||||
|
|
||||||
//Listen on default values
|
|
||||||
server.bind(12201, 'localhost');
|
|
||||||
},
|
},
|
||||||
'should receive log messages at the local gelf server': function(err, packet) {
|
'should receive log messages at the local gelf server': function(err, packet) {
|
||||||
assert.ok(packet.size > 0, "Recevied blank message");
|
assert.ok(fakeClient.packetLength > 0, "Recevied blank message");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).export(module);
|
}).export(module);
|
Loading…
Reference in New Issue
Block a user