Name: js-handler/node_modules/restify/node_modules/bunyan/examples/raw-stream.js
| 1: | // Example of a "raw" stream in a Bunyan Logger. A raw stream is one to |
| 2: | // which log record *objects* are written instead of the JSON-serialized |
| 3: | // string. |
| 4: | |
| 5: | var Logger = require('../lib/bunyan'); |
| 6: | |
| 7: | |
| 8: | /** |
| 9: | * A raw Bunyan Logger stream object. It takes raw log records and writes |
| 10: | * them to stdout with an added "yo": "yo" field. |
| 11: | */ |
| 12: | function MyRawStream() {} |
| 13: | MyRawStream.prototype.write = function (rec) { |
| 14: | if (typeof (rec) !== 'object') { |
| 15: | console.error('error: raw stream got a non-object record: %j', rec) |
| 16: | } else { |
| 17: | rec.yo = 'yo'; |
| 18: | process.stdout.write(JSON.stringify(rec) + '\n'); |
| 19: | } |
| 20: | } |
| 21: | |
| 22: | |
| 23: | // A Logger using the raw stream. |
| 24: | var log = new Logger({ |
| 25: | name: 'raw-example', |
| 26: | streams: [ |
| 27: | { |
| 28: | level: 'info', |
| 29: | stream: new MyRawStream(), |
| 30: | type: 'raw' |
| 31: | }, |
| 32: | ] |
| 33: | }); |
| 34: | |
| 35: | |
| 36: | log.info('hi raw stream'); |
| 37: | log.info({foo: 'bar'}, 'added "foo" key'); |
