redirect-function-output-streams
redirect a function's output streams
Last updated 2 years ago by cdaringe .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install redirect-function-output-streams 
SYNC missed versions from official npm registry.

redirect-function-output-streams

redirect stdout and/or stderr streams from within a function call. WAT!

streams are not primatives of functions--they are primatives of processes. however, it is feasible to isolate if stream content is being written within the context of a specific function's stack, and handle it.

var redirect = require('redirect-function-output-streams')
function a () {
  console.log('intercepted and streamed elsewhere')
  console.error('err msg!')
  void function a_child () {
    console.log('also intercepted and streamed elsewhere')
  }()
  somethingElse() // all other stdout writes, ...also streamed elsewhere
}
console.log('will show in stdout')
redirect({ stdout: someFileStream }, a)()

warning

  • this module uses long stack traces, and consequently may create perf issues. try it, test it.
  • if existing code intercepts process.std[out|err], all guarantees are off! IDEs for example, likely intercept streams before your code does, and may write anything they care to out!
  • don't redirect within a redirect. that's just uncool! :)
  • this module might be a mistake. maybe we should just be using process.fork(...), but hey.

Current Tags

  • 0.0.2                                ...           latest (2 years ago)

2 Versions

  • 0.0.2                                ...           2 years ago
  • 0.0.1                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (2)
  • hook-std github:cdaringe/hook-std#feat/add-original-stream
  • trace ^3.1.0
Dev Dependencies (11)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |