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 = require('console-redirect')
// redirect browser's console.log and console.error
// to the process stdout and stderr, respectively
redirect(process.stdout, process.stderr)
The following entry point registers the above, hooking into
process
stdout and stderr:require('console-redirect/process')
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 = require('console-redirect')
// listen for stdout
// ignore stderr
// do not write native methods
var logger = redirect(process.stdout, null, true)
// ... some time later, release it
logger.release()