log.Fatalf is mis-documented?

I noticed that Mage (magefile.org) appears to set the default logger (i.e., log.Default()’s return) to discard. This is its default behaviour; to change it you have to set Mage to “verbose” mode.

I was confused on this for a while because of this:

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

func Fatalf(format string, v ...any)
    Fatalf is equivalent to Printf() followed by a call to os.Exit(1).

In my case that wasn’t true, which confused multiple folks on my team.

Should this documentation be updated, or am I missing something? I’m thinking:

Fatalf is like fmt.Printf() followed by a call to os.Exit(1). Unlike Printf, though, Fatalf’s output goes to the standard logger’s output, which may or may 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.


Ahh, ok. Thank you for clarifying.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.