Skip to content

Instantly share code, notes, and snippets.

@wader
Last active January 27, 2021 00:29
Show Gist options
  • Save wader/03e856976352490426f8944f0ac33b9a to your computer and use it in GitHub Desktop.
Save wader/03e856976352490426f8944f0ac33b9a to your computer and use it in GitHub Desktop.
quick go logger writing to file
in program:
func init() {
if lf := os.Getenv("LOGFILE"); lf != "" {
log.SetOutput(func() io.Writer { f, _ := os.Create(lf); return f }())
}
}
or
func init() {
log.SetOutput(func() io.Writer { f, _ := os.Create("/tmp/log"); return f }())
}
or
log := log.New(func() io.Writer { f, _ := os.Create("/tmp/log"); return f }(), "", 0)
log.Printf("vs: %#+v\n", vs)
in other terminal:
tail -f /var/log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment