From b378560eac8b4d13d8b9b6964f170d1fab37b705 Mon Sep 17 00:00:00 2001 From: Dave Pacheco Date: Wed, 20 Jun 2012 16:26:28 -0700 Subject: [PATCH] use raw stream support --- README.md | 2 ++ bin/bunyan | 4 ++-- examples/ringbuffer.js | 1 + lib/bunyan.js | 11 ++--------- test/ringbuffer.test.js | 1 + 5 files changed, 8 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 84b3de3..075181d 100644 --- a/README.md +++ b/README.md @@ -476,6 +476,7 @@ To use a RingBuffer: var ringbuffer = new bunyan.RingBuffer({ limit: 100 }); var log = new bunyan({ name: "foo", + raw: true, stream: ringbuffer, level: "debug" }); @@ -487,6 +488,7 @@ This example emits: [ { name: 'foo', hostname: '912d2b29', + raw: true, pid: 50346, level: 30, msg: 'hello world', diff --git a/bin/bunyan b/bin/bunyan index 1494ba6..70bee22 100755 --- a/bin/bunyan +++ b/bin/bunyan @@ -212,10 +212,10 @@ function emitNextRecord(opts, stylize) continue; if (streams[ofile].records.length > 0) { - if (!streams[ofile].paused) { + if (!streams[ofile].paused) { streams[ofile].paused = true; streams[ofile].stream.pause(); - } + } } else if (streams[ofile].paused) { streams[ofile].paused = false; streams[ofile].stream.resume(); diff --git a/examples/ringbuffer.js b/examples/ringbuffer.js index 06d4cb3..4dd7842 100644 --- a/examples/ringbuffer.js +++ b/examples/ringbuffer.js @@ -3,6 +3,7 @@ var bunyan = require('..'); var ringbuffer = new bunyan.RingBuffer({ limit: 100 }); var log = new bunyan({ name: 'foo', + raw: true, stream: ringbuffer, level: 'debug' }); diff --git a/lib/bunyan.js b/lib/bunyan.js index 3a531b9..875c8b9 100644 --- a/lib/bunyan.js +++ b/lib/bunyan.js @@ -992,18 +992,11 @@ function RingBuffer(options) { util.inherits(RingBuffer, EventEmitter); -RingBuffer.prototype.write = function (str) { - var json; - +RingBuffer.prototype.write = function (record) { if (!this.writable) throw (new Error('RingBuffer has been ended already')); - try { - json = JSON.parse(str); - this.entries.push(json); - } catch (ex) { - this.entries.push(str); - } + this.entries.push(record); if (this.entries.length > this.limit) this.entries.shift(); diff --git a/test/ringbuffer.test.js b/test/ringbuffer.test.js index beefd3a..3589be5 100644 --- a/test/ringbuffer.test.js +++ b/test/ringbuffer.test.js @@ -11,6 +11,7 @@ var log1 = new Logger({ streams: [ { stream: ringbuffer, + raw: true, level: 'info' } ]