Life In The Stack Trace...

TODO: <Insert clever marketing phrase here>

Golang - Logging to a file

I couldn't find this answer in the officail documentation. If it exists, then, it eluded me.

Basically, all that you need to do is open a file and assign it to the standard logger using SetOutput().

// open a file
f, err := os.OpenFile("test.log", os.O_APPEND | os.O_CREATE | os.O_RDWR, 0666)
if err != nil {
  fmt.Printf("error opening file: %v", err)

// don't forget to close it
defer f.Close()

// assign it to the standard logger

Download the support file for this article and run the example.

Good luck!!