August 2019
Beginner to intermediate
798 pages
17h 2m
English
In this section, you will see the log.Fatal() function in action. The log.Fatal() function is used when something really bad has happened and you just want to exit your program as fast as possible after reporting the bad situation.
The use of log.Fatal() is illustrated in the logFatal.go program, which contains the following Go code:
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.Fatal(sysLog)
fmt.Println("Will you see this?")
}
Executing log.Fatal() will create the following output:
$ go run logFatal.go exit status 1
As you can easily understand, the use of
Read now
Unlock full access