null-logtron
A logger that no-ops
Example
var NullLogtron = ; var logger = ;loggerloggerloggerlogger
The NullLogger does not write anywhere. It actually writes to a circular buffer in memory (pre-allocated to 50).
Using in tests
You can use the .items()
method in your tests to read the
records that have been written to the logger.
var NullLogtron = ;var test = ; ;
Motivation
If your writing a library you want the application developer to pass in a logger. You cannot default a logger because that breaks the unix rule of silence.
So you either need a no-op logger or you need a ton of if statements. This is a cheap no-op logger.
I've chosen to back it by a RingBuffer so that if you do REPL into your process you can inspect the log statements.
The RingBuffer only holds 50 log records so the memory overhead is trivial.
Docs
// TODO. State what the module does.
Installation
npm install null-logtron
Tests
npm test
Contributors
- Raynos