Skip to content

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

Notifications You must be signed in to change notification settings

mk-pmb/log-stream-events-pmb-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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 (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

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published