Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

49 lines (33 sloc) 1.222 kb

eel-stream - EventEmitter logging -> writeable streams Build Status

An incredibly simple module for directing logs from eel to a writeable stream, just 6 lines:

module.exports = function (formatter, stream) {
    return function (entry) {
        var output = formatter(entry)
        if (!output) return
        stream.write(output + '\n')
    }
}

Usage

Install it like this:

npm install eel-stream

Use it like this:

var fs  = require('fs')
var log = require('eel')
var stream = fs.createWriteStream(__dirname+'/myapp.log')
var handler = require('eel-stream')(JSON.stringify, stream)

log.on('entry', handler)

log('test1', {ok: true})
log.error('test2', {ok: false})

And get log entries like this in myapp.log:

{"type":"test1","level":"info","timestamp":"2012-06-28T18:48:01.249Z","ok":true}
{"type":"test2","level":"error","timestamp":"2012-06-28T18:48:01.250Z","ok":false}

Parameters

  • formatter: A callback with the signature (entry) -> String|Buffer
  • stream: A writable stream

License

BSD

Jump to Line
Something went wrong with that request. Please try again.