From 1eed1fac1957703deb253eac388a98313d97c106 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Thu, 21 Jun 2012 14:53:05 -0700 Subject: [PATCH] use RingBuffer.records instead of RingBuffer.enties (related to pull #15) --- CHANGES.md | 2 +- README.md | 4 ++-- examples/ringbuffer.js | 4 ++-- lib/bunyan.js | 12 ++++++------ test/ringbuffer.test.js | 20 ++++++++++---------- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 50c955c..ea7d76a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -29,7 +29,7 @@ }); log.info('hello world'); - console.log(ringbuffer.entries); + console.log(ringbuffer.records); - Add support for "raw" streams. This is a logging stream that is given raw log record objects instead of a JSON-stringified string. diff --git a/README.md b/README.md index f291db8..5c8be9c 100644 --- a/README.md +++ b/README.md @@ -481,7 +481,7 @@ own HTTP interface, or a post-mortem facility like MDB or node-panic. To use a RingBuffer: - /* Create a ring buffer that stores the last 100 entries. */ + /* Create a ring buffer that stores the last 100 records. */ var bunyan = require('bunyan'); var ringbuffer = new bunyan.RingBuffer({ limit: 100 }); var log = new bunyan({ @@ -500,7 +500,7 @@ To use a RingBuffer: }); log.info('hello world'); - console.log(ringbuffer.entries); + console.log(ringbuffer.records); This example emits: diff --git a/examples/ringbuffer.js b/examples/ringbuffer.js index 6364fd0..74ffb31 100644 --- a/examples/ringbuffer.js +++ b/examples/ringbuffer.js @@ -1,4 +1,4 @@ -/* Create a ring buffer that stores the last 100 entries. */ +/* Create a ring buffer that stores the last 100 records. */ var bunyan = require('..'); var ringbuffer = new bunyan.RingBuffer({ limit: 100 }); var log = new bunyan({ @@ -11,4 +11,4 @@ var log = new bunyan({ }); log.info('hello world'); -console.log(ringbuffer.entries); +console.log(ringbuffer.records); diff --git a/lib/bunyan.js b/lib/bunyan.js index 5b7d1e4..bbb5a35 100644 --- a/lib/bunyan.js +++ b/lib/bunyan.js @@ -982,17 +982,17 @@ var errSerializer = Logger.stdSerializers.err = function err(err) { /** - * RingBuffer is a Writable Stream that just stores the last N entries in + * RingBuffer is a Writable Stream that just stores the last N records in * memory. * * @param options {Object}, with the following fields: * - * - limit: number of entries to keep in memory + * - limit: number of records to keep in memory */ function RingBuffer(options) { this.limit = options && options.limit ? options.limit : 100; this.writable = true; - this.entries = []; + this.records = []; EventEmitter.call(this); } @@ -1002,10 +1002,10 @@ RingBuffer.prototype.write = function (record) { if (!this.writable) throw (new Error('RingBuffer has been ended already')); - this.entries.push(record); + this.records.push(record); - if (this.entries.length > this.limit) - this.entries.shift(); + if (this.records.length > this.limit) + this.records.shift(); return (true); }; diff --git a/test/ringbuffer.test.js b/test/ringbuffer.test.js index 4f8ae61..75a6a12 100644 --- a/test/ringbuffer.test.js +++ b/test/ringbuffer.test.js @@ -21,19 +21,19 @@ test('ringbuffer', function (t) { log1.info('hello'); log1.trace('there'); log1.error('android'); - t.equal(ringbuffer.entries.length, 2); - t.equal(ringbuffer.entries[0]['msg'], 'hello'); - t.equal(ringbuffer.entries[1]['msg'], 'android'); + t.equal(ringbuffer.records.length, 2); + t.equal(ringbuffer.records[0]['msg'], 'hello'); + t.equal(ringbuffer.records[1]['msg'], 'android'); log1.error('one'); log1.error('two'); log1.error('three'); - t.equal(ringbuffer.entries.length, 5); + t.equal(ringbuffer.records.length, 5); log1.error('four'); - t.equal(ringbuffer.entries.length, 5); - t.equal(ringbuffer.entries[0]['msg'], 'android'); - t.equal(ringbuffer.entries[1]['msg'], 'one'); - t.equal(ringbuffer.entries[2]['msg'], 'two'); - t.equal(ringbuffer.entries[3]['msg'], 'three'); - t.equal(ringbuffer.entries[4]['msg'], 'four'); + t.equal(ringbuffer.records.length, 5); + t.equal(ringbuffer.records[0]['msg'], 'android'); + t.equal(ringbuffer.records[1]['msg'], 'one'); + t.equal(ringbuffer.records[2]['msg'], 'two'); + t.equal(ringbuffer.records[3]['msg'], 'three'); + t.equal(ringbuffer.records[4]['msg'], 'four'); t.end(); });