I'm trying to write output to a file whenever I print something to the console. There didn't seem to be any nice examples out there using a continuous stream, but rather reading a single value so I came up with the following code:
package main
import (
"fmt"
"io"
"os"
)
type ahhh struct {
*os.File
__writer io.Writer
}
func (me *ahhh) Write(b []byte) (n int, err error) {
return me.__writer.Write(b)
}
func write_print_to_file(file_name string) {
file, _ := os.OpenFile(file_name, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
new_stdout := &ahhh{file, io.MultiWriter(file, os.Stdout)}
os.Stdout = new_stdout
}
func main() {
write_print_to_file("output.log")
fmt.Println("Hello world!")
}
os.Stdout = new_stdoutos.Stdoutos.File
Alternatively if this really isn't possible any good suggestions for making a continuous data stream to a file?