August 2019
Beginner to intermediate
798 pages
17h 2m
English
There are situations where a program will fail for good and you want to have as much information about the failure as possible.
In such difficult times, you might consider using log.Panic(), which is the logging function that is illustrated in this section using the Go code of logPanic.go.
The Go code of logPanic.go is as follows:
package main
import (
"fmt"
"log"
"log/syslog"
)
func main() {
sysLog, err := syslog.New(syslog.LOG_ALERT|syslog.LOG_MAIL, "Some program!")
if err != nil {
log.Fatal(err)
} else {
log.SetOutput(sysLog)
}
log.Panic(sysLog)
fmt.Println("Will you see this?")
}
Executing logPanic.go on macOS Mojave will produce the following output:
$ go run logPanic.go
panic: &{17 Some program! iMac.local {0 0} 0xc0000b21e0} ...Read now
Unlock full access