use RingBuffer.records instead of RingBuffer.enties (related to pull #15)
This commit is contained in:
parent
37a1447f22
commit
1eed1fac19
5 changed files with 21 additions and 21 deletions
|
@ -29,7 +29,7 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
log.info('hello world');
|
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
|
- Add support for "raw" streams. This is a logging stream that is given
|
||||||
raw log record objects instead of a JSON-stringified string.
|
raw log record objects instead of a JSON-stringified string.
|
||||||
|
|
|
@ -481,7 +481,7 @@ own HTTP interface, or a post-mortem facility like MDB or node-panic.
|
||||||
|
|
||||||
To use a RingBuffer:
|
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 bunyan = require('bunyan');
|
||||||
var ringbuffer = new bunyan.RingBuffer({ limit: 100 });
|
var ringbuffer = new bunyan.RingBuffer({ limit: 100 });
|
||||||
var log = new bunyan({
|
var log = new bunyan({
|
||||||
|
@ -500,7 +500,7 @@ To use a RingBuffer:
|
||||||
});
|
});
|
||||||
|
|
||||||
log.info('hello world');
|
log.info('hello world');
|
||||||
console.log(ringbuffer.entries);
|
console.log(ringbuffer.records);
|
||||||
|
|
||||||
This example emits:
|
This example emits:
|
||||||
|
|
||||||
|
|
|
@ -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 bunyan = require('..');
|
||||||
var ringbuffer = new bunyan.RingBuffer({ limit: 100 });
|
var ringbuffer = new bunyan.RingBuffer({ limit: 100 });
|
||||||
var log = new bunyan({
|
var log = new bunyan({
|
||||||
|
@ -11,4 +11,4 @@ var log = new bunyan({
|
||||||
});
|
});
|
||||||
|
|
||||||
log.info('hello world');
|
log.info('hello world');
|
||||||
console.log(ringbuffer.entries);
|
console.log(ringbuffer.records);
|
||||||
|
|
|
@ -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.
|
* memory.
|
||||||
*
|
*
|
||||||
* @param options {Object}, with the following fields:
|
* @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) {
|
function RingBuffer(options) {
|
||||||
this.limit = options && options.limit ? options.limit : 100;
|
this.limit = options && options.limit ? options.limit : 100;
|
||||||
this.writable = true;
|
this.writable = true;
|
||||||
this.entries = [];
|
this.records = [];
|
||||||
EventEmitter.call(this);
|
EventEmitter.call(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1002,10 +1002,10 @@ RingBuffer.prototype.write = function (record) {
|
||||||
if (!this.writable)
|
if (!this.writable)
|
||||||
throw (new Error('RingBuffer has been ended already'));
|
throw (new Error('RingBuffer has been ended already'));
|
||||||
|
|
||||||
this.entries.push(record);
|
this.records.push(record);
|
||||||
|
|
||||||
if (this.entries.length > this.limit)
|
if (this.records.length > this.limit)
|
||||||
this.entries.shift();
|
this.records.shift();
|
||||||
|
|
||||||
return (true);
|
return (true);
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,19 +21,19 @@ test('ringbuffer', function (t) {
|
||||||
log1.info('hello');
|
log1.info('hello');
|
||||||
log1.trace('there');
|
log1.trace('there');
|
||||||
log1.error('android');
|
log1.error('android');
|
||||||
t.equal(ringbuffer.entries.length, 2);
|
t.equal(ringbuffer.records.length, 2);
|
||||||
t.equal(ringbuffer.entries[0]['msg'], 'hello');
|
t.equal(ringbuffer.records[0]['msg'], 'hello');
|
||||||
t.equal(ringbuffer.entries[1]['msg'], 'android');
|
t.equal(ringbuffer.records[1]['msg'], 'android');
|
||||||
log1.error('one');
|
log1.error('one');
|
||||||
log1.error('two');
|
log1.error('two');
|
||||||
log1.error('three');
|
log1.error('three');
|
||||||
t.equal(ringbuffer.entries.length, 5);
|
t.equal(ringbuffer.records.length, 5);
|
||||||
log1.error('four');
|
log1.error('four');
|
||||||
t.equal(ringbuffer.entries.length, 5);
|
t.equal(ringbuffer.records.length, 5);
|
||||||
t.equal(ringbuffer.entries[0]['msg'], 'android');
|
t.equal(ringbuffer.records[0]['msg'], 'android');
|
||||||
t.equal(ringbuffer.entries[1]['msg'], 'one');
|
t.equal(ringbuffer.records[1]['msg'], 'one');
|
||||||
t.equal(ringbuffer.entries[2]['msg'], 'two');
|
t.equal(ringbuffer.records[2]['msg'], 'two');
|
||||||
t.equal(ringbuffer.entries[3]['msg'], 'three');
|
t.equal(ringbuffer.records[3]['msg'], 'three');
|
||||||
t.equal(ringbuffer.entries[4]['msg'], 'four');
|
t.equal(ringbuffer.records[4]['msg'], 'four');
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue