1.0.6 • Published 9 years ago
log-stream-events-pmb v1.0.6
log-stream-events-pmb
Install logging handlers on a variety of stream-related events.
API
This module exports one function:
observe(subj[, name, logFunc])
subjshould be an EventEmitter, e.g. a Stream or a Socket.namecan be a name to use for reporting events onsubj. If omitted or false-y,observetries to guess a JSON-y name from properties ofsubj, e.g. an address or a file descriptor number.logFunccan be a function used to report the events. It can also be a string, in which case it's understood as the name of a method on the globalconsoleobject. If omitted or false-y,console.warnis used.
The observe function has these properties:
.evNamesis an array of event names to whichobservewill subscribe.
Usage
from test.usage.js:
var posixPipe = require('posix-pipe'), pair = posixPipe(),
rd = pair[0], wr = pair[1],
observeStreamEvents = require('log-stream-events-pmb');
observeStreamEvents(rd, '|->', test.log.args);
observeStreamEvents(wr, '->|', test.log.args);
function send(t, x) {
setTimeout(function () {
test.log.args('send:', x);
if (x === null) { wr.end(); } else { wr.write(x); }
}, t * 1000);
}
send(0.3, 'Hello ');
send(0.5, 'World!\n');
send(0.7, null);
setTimeout(test.log.verify, 1000);
test.log.expect = [
[ '|->', 'resume' ],
[ '->|', 'resume' ],
[ 'send:', 'Hello ' ],
[ '|->', 'data', 'buf[6] "Hello "' ],
[ 'send:', 'World!\n' ],
[ '|->', 'data', 'buf[7] "World!\\n"' ],
[ 'send:', null ],
[ '->|', 'finish' ],
[ '|->', 'readable' ],
[ '|->', 'end' ],
[ '|->', 'close', false ],
[ '->|', 'close', false ],
];Event names list
The last time this readme was updated, observe.evNames had:
abort aborted beforeExit change close connect connected connection continue cork data disconnect disconnected drain end error exit finish line listen listening lookup message open pause pipe readable ready request reset resize response resume secureConnect socket start stop sync timeout uncork unpipe upgrade warning writable writeable
Known issues
- needs more/better tests and docs
License
ISC