Skip to content

Commit

Permalink
add; gelf 1.1 and optional microtime dep
Browse files Browse the repository at this point in the history
  • Loading branch information
wavded committed Aug 21, 2014
1 parent d7f4864 commit d4d2470
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
8 changes: 6 additions & 2 deletions 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 })
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -22,5 +22,8 @@
"engines": {
"node": ">= 0.10.0"
},
"dependencies": {}
"dependencies": {},
"optionalDependencies": {
"microtime": "^1.0.1"
}
}
2 changes: 1 addition & 1 deletion test/client-test.js
Expand Up @@ -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')
Expand Down
12 changes: 6 additions & 6 deletions test/server-test.js
Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand Down

0 comments on commit d4d2470

Please sign in to comment.