1.0.0 • Published 10 years ago
winston-circular-buffer v1.0.0
Winston Circular buffer
An in-memory circular buffer logging transport for the winston.js node.js logging system.
This transport allows a simple most-recent view of log entries from a bounded circular buffer. Useful if you just want to see whats recently happened without having to manage growing memory usage, file rotation etc.
Usage
Specify the size of the buffer when adding the transport:
var winston = require('winston');
var cbuff = require('winston-circular-buffer');
var logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)(),
new (winston.transports.CircularBuffer)({
name: 'circular-buffer',
level: 'info',
json: true,
size: 50
})
]
});Log as usual, and query the buffer:
logger.warn('my warning', { meta: 21 });
var options = {
json: true,
order: 'asc'
};
logger.query(options, function(err, results) {
// Check err, handle results array
});The query options are:
json:set totrue(default) if you want the records to be json objects,falsefor strings (note that if the transport has been configured forjson: falsethen you will always get strings returned).order:set to'desc'(default) to produce descending order results (most recent first). Useorder: 'asc'for ascending output.
Install
npm installTest
npm testAuthor
(c) Jonathan Perkins 2015.
Feedback, bug reports welcome via https://github.com/JonathanPerkins/winston-circular-buffer
1.0.0
10 years ago