Ensure that the node logs are in UTF-8.

Since the printed node logs might include ANSI escapes or other bytes
> 127, we must transcode them to UTF-8 before slurping them into JSON.

This commit also reformats a function that was badly indented.