Thursday, April 25, 2024
HomeGolanglog.Fatalf is mis-documented? - Getting Assist

log.Fatalf is mis-documented? – Getting Assist


I observed that Mage (magefile.org) seems to set the default logger (i.e., log.Default()’s return) to discard. That is its default behaviour; to alter it you must set Mage to “verbose” mode.

I used to be confused on this for some time due to this:

> go doc log.Fatalf
bundle log // import "log"

func Fatalf(format string, v ...any)
    Fatalf is equal to Printf() adopted by a name to os.Exit(1).

In my case that wasn’t true, which confused a number of people on my staff.

Ought to this documentation be up to date, or am I lacking one thing? I’m pondering:

Fatalf is like fmt.Printf() adopted by a name to os.Exit(1). Not like Printf, although, Fatalf’s output goes to the usual logger’s output, which can or will not be os.Stdout.

The documentation doesn’t say it behaves like fmt.Printf. It says it behaves like Printf (i.e. log.Printf), which behaves as you described it.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments