diff --git a/lib/client.js b/lib/client.js index 17c7494..dca2efb 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1,4 +1,8 @@ "use strict"; +var time +try { time = require('microtime') } +catch (e) { time = Date } + var LOG_LEVELS = ['emerg','alert','crit','error','warn','notice','info','debug'] var LOG_LEVEL_PRIORITIES = Object.create(null) LOG_LEVELS.forEach(function (level, priority) { LOG_LEVEL_PRIORITIES[level] = priority }) @@ -79,10 +83,10 @@ GrayGelf.prototype._prepJson = function ( /*level, short, full*/ ) { this.emit('message', LOG_LEVELS[level], short, full) var gelf = { - version: '1.0', + version: '1.1', host: this.hostname, short_message: Buffer.isBuffer(short) ? short.toString() : short, - timestamp: Date.now() / 1000 >> 0, + timestamp: time.now() / 1000 >> 0, level: level, facility: this.facility } diff --git a/package.json b/package.json index b0a7dd1..73dc160 100644 --- a/package.json +++ b/package.json @@ -22,5 +22,8 @@ "engines": { "node": ">= 0.10.0" }, - "dependencies": {} + "dependencies": {}, + "optionalDependencies": { + "microtime": "^1.0.1" + } } diff --git a/test/client-test.js b/test/client-test.js index 52e13e0..f46dc94 100644 --- a/test/client-test.js +++ b/test/client-test.js @@ -72,7 +72,7 @@ suite('gelf messages', function () { test('sets up proper gelf message', function () { var gelf = gg._prepJson(0, 'my message', { addn: 'data', _extra: 'field', _id: '2323232323' }) - assert.equal(gelf.version, '1.0', 'should have version: 1.0') + assert.equal(gelf.version, '1.1', 'should have version: 1.1') assert.equal(gelf.host, os.hostname(), 'should use os.hostname for host') assert.equal(gelf.short_message, 'my message', 'should include short_message') assert.equal(gelf.full_message.addn, 'data', 'should include full_message') diff --git a/test/server-test.js b/test/server-test.js index 10b3653..18dc741 100644 --- a/test/server-test.js +++ b/test/server-test.js @@ -39,7 +39,7 @@ suite('deflate compress type', function () { test('handles gelf messages', function (done) { server.once('message', function (gelf) { - assert.equal(gelf.version, '1.0', 'should have version: 1.0') + assert.equal(gelf.version, '1.1', 'should have version: 1.1') assert.equal(gelf.host, os.hostname(), 'should use os.hostname for host') assert.equal(gelf.short_message, 'my message', 'should include short_message') assert.equal(gelf.full_message.addn, 'data', 'should include full_message') @@ -56,7 +56,7 @@ suite('deflate compress type', function () { test('handles chunked messages', function (done) { client.chunkSize = 10 server.once('message', function (gelf) { - assert.equal(gelf.version, '1.0', 'should have version: 1.0') + assert.equal(gelf.version, '1.1', 'should have version: 1.1') assert.equal(gelf.host, os.hostname(), 'should use os.hostname for host') assert.equal(gelf.short_message, 'my message', 'should include short_message') assert.equal(gelf.full_message.addn2, 'more data', 'should include full_message') @@ -72,7 +72,7 @@ suite('deflate compress type', function () { test('handles out of order chunked messages', function (done) { server.once('message', function (gelf) { - assert.equal(gelf.version, '1.0', 'should have version: 1.0') + assert.equal(gelf.version, '1.1', 'should have version: 1.1') assert.equal(gelf.host, os.hostname(), 'should use os.hostname for host') assert.equal(gelf.short_message, 'my message', 'should include short_message') assert.equal(gelf.full_message.addn2, 'more data', 'should include full_message') @@ -114,7 +114,7 @@ suite('gzip compress type', function () { test('handles gelf messages', function (done) { server.once('message', function (gelf) { - assert.equal(gelf.version, '1.0', 'should have version: 1.0') + assert.equal(gelf.version, '1.1', 'should have version: 1.1') assert.equal(gelf.host, os.hostname(), 'should use os.hostname for host') assert.equal(gelf.short_message, 'my message', 'should include short_message') assert.equal(gelf.full_message.addn2, 'more data', 'should include full_message') @@ -131,7 +131,7 @@ suite('gzip compress type', function () { test('handles chunked messages', function (done) { client.chunkSize = 10 server.once('message', function (gelf) { - assert.equal(gelf.version, '1.0', 'should have version: 1.0') + assert.equal(gelf.version, '1.1', 'should have version: 1.1') assert.equal(gelf.host, os.hostname(), 'should use os.hostname for host') assert.equal(gelf.short_message, 'my message', 'should include short_message') assert.equal(gelf.full_message.addn2, 'more data', 'should include full_message') @@ -147,7 +147,7 @@ suite('gzip compress type', function () { test('handle out of order chunked messages', function (done) { server.once('message', function (gelf) { - assert.equal(gelf.version, '1.0', 'should have version: 1.0') + assert.equal(gelf.version, '1.1', 'should have version: 1.1') assert.equal(gelf.host, os.hostname(), 'should use os.hostname for host') assert.equal(gelf.short_message, 'my message', 'should include short_message') assert.equal(gelf.full_message.addn2, 'more data', 'should include full_message')