subjlog1707-pmb
v1.0.3
Published
Log messages to memory with a subject.
Readme
subjlog1707-pmb
Log messages to memory with a subject.
This module logs to memory.
If you want to log to your default console with a topic, use the similarly-named module with a "c" (for "console") in its name, subjclog2607-pmb.
Usage
from test.usage.js:
var makeLogger = require('subjlog1707-pmb'), someObj = /some regexp/ig,
myLogger = makeLogger(someObj), cb, ar;
equal(myLogger.subj, someObj);
myLogger('A logger for', 'some object:', String(myLogger));
cb = myLogger.l8r('.l8r(non-array) prepares a callback');
cb('that logs exactly', 'its original arguments', 'and ignores these.');
cb = myLogger.l8r([ '.l8r(array)', 'also logs' ]);
ar = [ 'the', 'callback', 'args' ];
ar.forEach(cb);
console.log = makeLogger('fake console');
myLogger.cfg({ verbose: true });
myLogger('Verbose mode on!');
myLogger.cfg({ verbose: false });
myLogger('… and off again.');
equal.lists(myLogger(), [
[ 'A logger for', 'some object:', '[logger for /some regexp/gi]' ],
'.l8r(non-array) prepares a callback',
[ '.l8r(array)', 'also logs', 'the', 0, ar ],
[ '.l8r(array)', 'also logs', 'callback', 1, ar ],
[ '.l8r(array)', 'also logs', 'args', 2, ar ],
'Verbose mode on!', '… and off again.',
]);
equal.lists(console.log(), [
[ '/some regexp/gi:', 'Verbose mode on!' ],
]);Known issues
- needs more/better tests and docs
License
ISC
