Skip to content

Commit

Permalink
Floats and Integers aren't supported, closes #10
Browse files Browse the repository at this point in the history
  • Loading branch information
kkamkou committed Mar 22, 2016
1 parent 04c7d05 commit 0214f55
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/gelf-pro.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ gelf.getStringFromObject = function (obj) {
if (_.isPlainObject(value)) {
return recursion(value, prefix ? [prefix, key].join('_') : key);
}
result[(prefix ? [null, prefix, key] : [null, key]).join('_')] = _.toString(value);
result[(prefix ? [null, prefix, key] : [null, key]).join('_')] =
_.isFinite(value) ? value : _.toString(value);
});
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gelf-pro",
"version": "0.6.1",
"version": "0.6.2",
"main": "./lib/gelf-pro.js",
"author": "Kanstantsin Kamkou <[email protected]>",
"description": "The Graylog Extended Log Format for the Node.js",
Expand Down
9 changes: 9 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ module.exports = {
JSON.parse(gelf.getStringFromObject({test: date}))._test.should.equal(date.toString());
},

'Work with numeric type': function () {
var gelf = _.cloneDeep(gelfOriginal),
fields = {aFloat: 1.1, anInteger: 0, aString: '0'},
json = JSON.parse(gelf.getStringFromObject(fields));
Number.isFinite(json._aFloat).should.equal(true);
Number.isFinite(json._anInteger).should.equal(true);
Number.isFinite(json._aString).should.equal(false);
},

'Transform an Error object': function () {
var gelf = _.cloneDeep(gelfOriginal),
err = new Error('Some error message');
Expand Down

0 comments on commit 0214f55

Please sign in to comment.