How do you capture logs and write them to `stderr`?

so basically my script outputs the result of Code.eval_string in json format.

But when I run the following:

mix run script.exs 'IO.puts("foobar")'

I get:

foobar
{"result":"ok"}

I would like to catch foobar as well, not ok only.