BetterErrors / better_errors

Better error page for Rack apps
MIT License
6.88k stars 437 forks source link

How to view stdout through console? #468

Open joshweir opened 4 years ago

joshweir commented 4 years ago

I would like to view stdout in the better_errors console. Specifically it's much easier to view a large object via pretty_generate, for example something like this (output in irb):

>> puts JSON.pretty_generate({ foo: 'bar' })
{
  "foo": "bar"
}
=> nil

but the better_errors console does not provide stdout for puts, and JSON.pretty_generate doesn't stdout either:

>> JSON.pretty_generate({ foo: 'bar' })
=> "{\n  \"foo\": \"bar\"\n}"
>> puts JSON.pretty_generate({ foo: 'bar' })
=> nil

Is there a way to do this?

RobinDaugherty commented 4 years ago

When a command is run through the console, the output is visible in the Rails server process output along with all of the other output.

Capturing output might be a feature we could add, but I suspect it would be difficult to redirect/replace the stdout stream. Considering that rails servers are usually multithreaded, I don't know if there's a clean way to make that work.