Conclusion: Read the documentation properly when using the API (´ ・ ω ・ `)
The go languages log.Fatal
, log.Fatalf
and log.Fatalln
issueos.Exit (1)
after the message is output and try to terminate the process. For example, suppose you have the following program.
main.go
package main
import (
"fmt"
"log"
)
func main() {
fmt.Println("BEFORE")
log.Fatalln("FATAL")
fmt.Println("AFTER")
}
If you build and run this, you will see that the program has exited with exit status 1 after outputting FATAL
(AFTER
is not output).
$ go build .
$
$ ./fataltest
BEFORE
2020/11/15 21:02:55 FATAL
$
$ echo $?
1
Some other programming languages and libraries have FATAL as the log level. In short, if you use a function of the log.Fatal
type thinking" Is it the one that outputs the FATAL level log! ", It may cause an unexpected bug--or rather, I did. Reflection)
reference