Last active
August 26, 2016 19:18
-
-
Save flowerinthenight/29d147a50242198f082fd33f7d24677c to your computer and use it in GitHub Desktop.
Output Go's log function to syslog.
This file contains 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
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