Skip to content

Commit

Permalink
Merge pull request #21 from kkamkou/issue-20
Browse files Browse the repository at this point in the history
Do not send an empty message, closes #20
  • Loading branch information
kkamkou authored Aug 31, 2016
2 parents d13f73a + a1ba752 commit c0fd765
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.idea/
/node_modules/
/coverage/
*.log
2 changes: 2 additions & 0 deletions lib/gelf-pro.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ gelf.send = function (message, cb) {
* @param {Function} cb
*/
gelf.message = function (message, lvl, extra, cb) {
if (_.isNil(message)) { return; }

// it is possible to skip the extra variable
if (_.isFunction(extra) && !cb) {
cb = extra;
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gelf-pro",
"version": "0.8.1",
"version": "0.8.2",
"main": "./lib/gelf-pro.js",
"author": "Kanstantsin Kamkou <[email protected]>",
"description": "The Graylog Extended Log Format for the Node.js",
Expand All @@ -17,7 +17,7 @@
"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"
},
"dependencies": {
"lodash": "~4.14",
"lodash": "~4.15",
"async": "~2.0"
},
"devDependencies": {
Expand Down
20 changes: 20 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,26 @@ module.exports = {

},

'Avoid an empty message': function (done) {
var gelf = _.cloneDeep(gelfOriginal);
sinon.spy(gelf, 'send');
gelf.message();
process.nextTick(function () {
gelf.send.calledOnce.should.be.false();
done();
});
},

'Avoid a message with null': function (done) {
var gelf = _.cloneDeep(gelfOriginal);
sinon.spy(gelf, 'send');
gelf.message();
process.nextTick(function () {
gelf.send.calledOnce.should.be.false();
done();
});
},

'Work with dates': function () {
var gelf = _.cloneDeep(gelfOriginal),
date = new Date();
Expand Down

0 comments on commit c0fd765

Please sign in to comment.