I’m working on some mechanism to collect all the console messages into a variable. This kind of behaviour should be limited to the lifespan of some function.
I’m using the EventEmitter to signal the beginning and the execution of the target function:
# in the function module/class onWillComputeStuff: (callback) -> @emitter.on 'will-compute-stuff', callback onDidComputeStuff: (callback) -> @emitter.on 'did-compute-stuff', callback doYourThing: () -> @emitter.emit 'will-compute-stuff' # here I do all my awesome stuff console.log 'this should be catch!' @emitter.emit 'did-compute-stuff'
What I do when I use this module is:
startConsoleIntercept: () -> @oldConsole = console.log newConsole = (message) => @capturedConsole += 'woow!' console.log = newConsole stopConsoleIntercept: () -> console.log = @oldConsole ... @subscriptions.add @emitterModule.onWillComputeStuff @startConsoleIntercept @subscriptions.add @emitterModule.onDidComputeStuff @stopConsoleIntercept
Unfortunately, this code does not seem to work. The
@capturedConsole variable is empty when my execution is done.
I also tried with some packages for stdout redirections, such as this one, but they just have the same behaviour.
Has anyone worked with
console.log in Atom before?