2012-06-20 23:04:23 +00:00
|
|
|
// Example of a "raw" stream in a Bunyan Logger. A raw stream is one to
|
|
|
|
// which log record *objects* are written instead of the JSON-serialized
|
|
|
|
// string.
|
|
|
|
|
|
|
|
var Logger = require('../lib/bunyan');
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A raw Bunyan Logger stream object. It takes raw log records and writes
|
|
|
|
* them to stdout with an added "yo": "yo" field.
|
|
|
|
*/
|
|
|
|
function MyRawStream() {}
|
|
|
|
MyRawStream.prototype.write = function (rec) {
|
2012-06-20 23:27:41 +00:00
|
|
|
if (typeof (rec) !== 'object') {
|
2012-06-20 23:04:23 +00:00
|
|
|
console.error('error: raw stream got a non-object record: %j', rec)
|
|
|
|
} else {
|
|
|
|
rec.yo = 'yo';
|
|
|
|
process.stdout.write(JSON.stringify(rec) + '\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// A Logger using the raw stream.
|
|
|
|
var log = new Logger({
|
|
|
|
name: 'raw-example',
|
|
|
|
streams: [
|
|
|
|
{
|
2012-06-20 23:27:41 +00:00
|
|
|
level: 'info',
|
2012-06-20 23:04:23 +00:00
|
|
|
stream: new MyRawStream(),
|
2012-06-21 21:49:04 +00:00
|
|
|
type: 'raw'
|
2012-06-20 23:04:23 +00:00
|
|
|
},
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
log.info('hi raw stream');
|
|
|
|
log.info({foo: 'bar'}, 'added "foo" key');
|