record-sink

2.0.2 • Public • Published

record-sink

NPM Version Build Status Coverage Status

Sink for records where the final processing and serialization happens.

Installation

npm install --save record-sink

Usage

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")

/record-sink/

    Package Sidebar

    Install

    npm i record-sink

    Weekly Downloads

    3

    Version

    2.0.2

    License

    ISC

    Last publish

    Collaborators

    • keis