console-redirect
Redirects console methods to the given writable streams. For example, can be used to redirect browser console
to process.stdout
and process.stderr
.
Install
npm install console-redirect --save
Example
var redirect = // redirect browser's console.log and console.error// to the process stdout and stderr, respectively
The following entry point registers the above, hooking into process
stdout and stderr:
Usage
log = redirect([stdout], [stderr], [replace])
Directs console
methods to the given stdout
and stderr
writable streams (which can be null).
The warn
and error
methods are directed to stderr
, the rest to stdout
.
If replace
is true (default false), it will not trigger the original method. In the context of a browser, this means it will not print to the terminal.
Return an object with the function release
, which can be used to reset the console log methods to their original.
var redirect = // listen for stdout// ignore stderr// do not write native methodsvar logger = // ... some time later, release itlogger
License
MIT, see LICENSE.md for details.