I would like to redirect stderr
to a file AND to stdout
.
I know how redirect stderr
to file using dup2
:err := syscall.Dup2(int(fatal_logfile.Fd()), int(os.Stderr.Fd()))
But then I don't see how can redirect this another time to stdout
. Like "copying" one stream-source to two differents streams.
Just a note, this functionality is called when the app starts and used to redirect stderr
when, for example, a panic
occurs. Then I cannot use recover
in this case (even because I am running lots of goroutines).
Anyone has an idea how to solve this?
Another working solution is to use pipes
and tee
when calling the binary, but is possible to have the same behavior/logic defined inside the app? I would like that it runs in this way as default.
./app_bin 2> >(tee -a fatal.log)