Last active
January 27, 2021 00:29
-
-
Save wader/03e856976352490426f8944f0ac33b9a to your computer and use it in GitHub Desktop.
quick go logger writing to file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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