Standard library / log

log.Fatalf()

Write a message then call os.Exit(1). Deferred functions do not run. Avoid this in reusable libraries. Expected stdout: 'count=2\n'. Expected exit status 1; run only as a standalone process.

Formal Syntax & Structure

go syntaxgo
func Fatalf(format string, v ...any)

Parameters & Attributes

NameTypeDescription
formatstringPrintf-style format string.
v...anyValues to log or convert.

Working Example

Example Snippetgo
package main
import (  "fmt"  "log"  "os")
func main() {  log.SetOutput(os.Stdout)  log.SetFlags(0)  log.SetPrefix("")  defer fmt.Println("not executed")  log.Fatalf("count=%d", 2)}
Go Reference