log-stream-events-pmb

1.0.6 • Public • Published

log-stream-events-pmb

Install logging handlers on a variety of stream-related events.

API

This module exports one function:

observe(subj[, name[, logFunc]])

  • subj should be an EventEmitter, e.g. a Stream or a Socket.
  • name can be a name to use for reporting events on subj. If omitted or false-y, observe tries to guess a JSON-y name from properties of subj, 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 global console object. If omitted or false-y, console.warn is used.

The observe function has these properties:

  • .evNames is an array of event names to which observe will 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 (=== 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

Readme

Keywords

Package Sidebar

Install

npm i log-stream-events-pmb

Weekly Downloads

2

Version

1.0.6

License

ISC

Last publish

Collaborators

  • mk-pmb