gelf-pro
Advanced tools
Comparing version 0.5.0 to 0.5.1
@@ -36,2 +36,11 @@ /** | ||
/** | ||
* Creates a new dgram.Socket object | ||
* @returns {dgram.Socket} | ||
* @private | ||
*/ | ||
udp._createSocket = function () { | ||
return dgram.createSocket(this.options.protocol); | ||
}; | ||
/** | ||
* Splits a buffer into chunks | ||
@@ -57,3 +66,3 @@ * @param {Buffer} buffer | ||
udp.send = function (message, callback) { | ||
var client = dgram.createSocket(this.options.protocol), | ||
var client = this._createSocket(), | ||
bytesSentTotal = 0, | ||
@@ -60,0 +69,0 @@ self = this; |
{ | ||
"name": "gelf-pro", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"main": "./lib/gelf-pro.js", | ||
@@ -22,3 +22,3 @@ "author": "Kanstantsin Kamkou <kkamkou@gmail.com>", | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage" | ||
}, | ||
@@ -30,6 +30,9 @@ "dependencies": { | ||
"devDependencies": { | ||
"istanbul": "~0.4.2", | ||
"should": "~8.2", | ||
"mocha": "~2.4", | ||
"mocha-lcov-reporter": "~1.2.0", | ||
"coveralls": "~2.11.8", | ||
"sinon": "~1.17" | ||
} | ||
} |
@@ -6,2 +6,3 @@ node-gelf pro | ||
![Build Status](https://travis-ci.org/kkamkou/node-gelf-pro.svg?branch=master) | ||
[![Coverage Status](https://coveralls.io/repos/github/kkamkou/node-gelf-pro/badge.svg?branch=master)](https://coveralls.io/github/kkamkou/node-gelf-pro?branch=master) | ||
@@ -24,9 +25,11 @@ ## Installation | ||
log.setConfig({ | ||
fields: {facility: "example", owner: "Tom (a cat)"}, // default fields for all messages | ||
adapterName: 'udp', // currently supported "udp" and "tcp" | ||
fields: {facility: "example", owner: "Tom (a cat)"}, // optional; default fields for all messages | ||
filter: [], // optional; filters to discard a message | ||
broadcast: [], // optional; listeners of a message | ||
adapterName: 'udp', // optional; currently supported "udp" and "tcp"; default: udp | ||
adapterOptions: { | ||
protocol: 'udp4', // udp only. udp adapter: udp4, udp6 | ||
family: 4, // tcp only, optional. Version of IP stack. Defaults to 4. | ||
host: '127.0.0.1', | ||
port: 12201 | ||
protocol: 'udp4', // udp only; optional; udp adapter: udp4, udp6; default: udp4 | ||
family: 4, // tcp only; optional; version of IP stack; default: 4 | ||
host: '127.0.0.1', // optional; default: udp4 | ||
port: 12201 // optional; default: 12201 | ||
} | ||
@@ -55,4 +58,4 @@ }); | ||
filter: [ | ||
function (message, extra) { // rejects a "debug" message | ||
return (extra.level < 5); | ||
function (message) { // rejects a "debug" message | ||
return (message.level < 5); | ||
} | ||
@@ -59,0 +62,0 @@ ] |
@@ -184,5 +184,6 @@ 'use strict'; | ||
adapter = gelf.getAdapter(), | ||
message = getLongMessage(100); | ||
message = getLongMessage(100), | ||
sandbox = sinon.sandbox.create(); | ||
sinon.stub(adapter, 'getArrayFromBuffer', function (msg, len) { | ||
sandbox.stub(adapter, 'getArrayFromBuffer', function (msg, len) { | ||
return new Array(adapter.specification.chunkMaxLength.udp4); | ||
@@ -194,4 +195,30 @@ }); | ||
should.not.exist(result); | ||
sandbox.restore(); | ||
done(); | ||
}); | ||
}, | ||
'Socket exception': function (done) { | ||
var gelf = _.cloneDeep(gelfOriginal), | ||
msgError = 'example', | ||
dgramSocket = require('dgram').createSocket('udp4'), | ||
mock = sinon.mock(dgramSocket).expects('close').once() | ||
sinon.stub(dgramSocket, 'send', function (msg, offset, length, port, address, cb) { | ||
msg.should.be.an.instanceof(Buffer); | ||
offset.should.equal(0); | ||
length.should.equal(24); | ||
port.should.equal(12201); | ||
address.should.equal('127.0.0.1'); | ||
cb(new Error(msgError)); | ||
}); | ||
sinon.stub(gelf.getAdapter(), '_createSocket').returns(dgramSocket); | ||
gelf.send('test', function (err, result) { | ||
mock.verify(); | ||
err.message.should.equal(msgError); | ||
should.not.exist(result); | ||
done(); | ||
}); | ||
} | ||
@@ -198,0 +225,0 @@ }, |
Sorry, the diff of this file is not supported yet
26441
17
571
118
6
3