Skip to content

Instantly share code, notes, and snippets.

@flowerinthenight
Last active August 26, 2016 19:18
Show Gist options
  • Save flowerinthenight/29d147a50242198f082fd33f7d24677c to your computer and use it in GitHub Desktop.
Save flowerinthenight/29d147a50242198f082fd33f7d24677c to your computer and use it in GitHub Desktop.
Output Go's log function to syslog.
package main
import (
"log"
"log/syslog"
"os"
)
func main() {
trace, err := syslog.New(syslog.LOG_INFO, "myapp")
if err != nil {
log.Println("Cannot open syslog. Terminate.")
os.Exit(-1)
}
defer func() {
log.Println("Closing myapp.")
trace.Close()
}()
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
log.SetOutput(trace)
log.Println("Hello world!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment