package main import ( "log" ) func main() { name := "Go" log.Printf("Hello %s World", name) }
package main import ( "log" "os" ) func main() { f, err := os.Open("file.txt") if err != nil { log.Fatalf("Failed to open file: %v", err) } defer f.Close() // Code to read from file }In this example, we use the Logger Printf method to log a fatal error message if the file `file.txt` fails to open. We also defer the closure of the file to ensure it is closed after being read from. If the file fails to open, the program will exit with a non-zero exit code. Package library: `"log"` (part of the standard library)