From 0214f551b30c9a7eb63c6f3a65a13165e8ac46af Mon Sep 17 00:00:00 2001 From: Kanstantsin Kamkou Date: Tue, 22 Mar 2016 15:57:50 +0100 Subject: [PATCH] Floats and Integers aren't supported, closes #10 --- lib/gelf-pro.js | 3 ++- package.json | 2 +- test/tests.js | 9 +++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/gelf-pro.js b/lib/gelf-pro.js index ac987e5..0808879 100644 --- a/lib/gelf-pro.js +++ b/lib/gelf-pro.js @@ -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); }); }; diff --git a/package.json b/package.json index e625713..6f94095 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gelf-pro", - "version": "0.6.1", + "version": "0.6.2", "main": "./lib/gelf-pro.js", "author": "Kanstantsin Kamkou ", "description": "The Graylog Extended Log Format for the Node.js", diff --git a/test/tests.js b/test/tests.js index f23f1ca..179d0ad 100644 --- a/test/tests.js +++ b/test/tests.js @@ -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');