Install logging handlers on a variety of stream-related events.
This module exports one function:
subj
should be an EventEmitter, e.g. a Stream or a Socket.name
can be a name to use for reporting events onsubj
. If omitted or false-y,observe
tries to guess a JSON-y name from properties ofsubj
, e.g. an address or a file descriptor number.logFunc
can 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 globalconsole
object. If omitted or false-y,console.warn
is used.
The observe
function has these properties:
.evNames
is an array of event names to whichobserve
will subscribe.
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 ],
];
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
- needs more/better tests and docs
ISC