Sink for records where the final processing and serialization happens.
npm install --save record-sink
This module is building block for creating message logging system and as such doesn't do much on it's own. By combining it with some stream magic it's possible to create a quick and dirty log method that writes neatly formatted log entries to stderr and to a file.
var Sink = require('record-sink')
, Record = require('log-record')
, through2 = require('through2')
, fs = require('fs')
, logger
logger = through2.obj({objectMode: true}, function (data, enc, cb) {
cb(null, data)
})
logger.pipe(new Sink())
logger.pipe(new Sink(fs.createWriteStream('application.log')))
function log() {
var args = Array.prototype.slice.call(arguments)
, msg = args.shift()
, record = new Record('main', 20, new Date(), msg, args)
logger.write(record)
}
log("hello %s", "world")