My program outputs a lot of text.
I use VSCode (relatively new) and the display of output is always truncated.
Is it possible to output all such fmt.PrintXXX statements to a file?
OR
How can I capture all of the output from the .Print statements ?
The way that I would recommend redirecting your output, would be to use the fmt.Fprint*
family of functions, and specify an io.Writer
that you want to write to. The io.Writer can be whatever you need, from an in memory buffer, to a file on your system, or even an open network connection. The fmt.Print*
functions are implemented by calling the fmt.Fprint*
functions and specifying os.Stdout
as the io.Writer
.
Because of the way the fmt.Print*
functions are defined, it should technically be possible to set os.Stdout
to a new *os.File
in order to redirect the output of anything that writes to stdout, including the fmt.Print*
functions. This is really not recommended, but possible.