Tonsole
Wrapper around Node's console that adds return values to logging calls.
This is useful for logging expressions and arrow functions without having to change any code.
const tonsole = ; let data ? processdatavalue : data; // normally we can't easily log what `compute` does without// rewriting it to use statements { if data const r = processdatavalue; console; return r; console; return data;}; // But with tonsole, we can add logging while still using// expressions, just as the ancient ones of Lisp intended. data ?tonsole
Usage
$ npm install --save tonsole
Tonsole provides a complete wrapper around the entire Node console api. All functions forward to the wrapped Node console implementation.
tonsole.Console(stdout [, stderr])
Wrapper around console.Console
. Logging methods of this class return values besides logging.
tonsole.log(...args)
tonsole.info(...args)
tonsole.warn(...args)
tonsole.error(...args)
Each of these methods logs using the inner console.*
method, but instead of returning undefined
, they return the last argument value.
tonsole;// Logs: "2 : 3"// returns 3
tonsole.assert(value, ...args)
Verify that value
is truthy using console.assert
but returns value
. If value
is falsy, an AssertionError
is thrown.
tonsole === 5 tonsole // throws AssertionError
tonsole.dir(obj, options)
Simply wrapper around console.dir
that returns obj
.
tonsole.time(label)
tonsole.timeEnd(label)
tonsole.trace(msg, ...)
Forward directly to console.*
and continue to return undefined.