Golang记录器致命

package main

import (
        "bytes"
        "fmt"
        "log"
)

func main() {   
        // Log into byte
        var buf bytes.Buffer
        logInfo := log.New(&buf, "[Info] ", log.Lshortfile)
        logInfo.Print("Hello, log file!")
        logInfo.Printf("Hello, %s", "crazy")
        fmt.Print(&buf)
        logInfo.Fatalln("Ut oh")
        fmt.Print(&buf)
   }

Hello. I am trying to use log.Fatal or log.Fatalln instead of having log.New and os.Exit. However, it seems like the logger does not log "Ut oh" part (logInfo.Fatalln)

Following is expected output:

[Info] main.go:17: Hello, log file!
[Info] main.go:18: Hello, crazy
[Info] main.go:17: Hello, log file!
[Info] main.go:18: Hello, crazy
[Info] main.go:xx: Ut oh

Following is what I got:

[Info] main.go:17: Hello, log file!
[Info] main.go:18: Hello, crazy

it seems like it didn't do anything from logInfo.Fatalln("Ut oh")

Could you please tell me what I missed? Thank you

log.Fatalln exits your app, so the second fmt.Print(&buf) does not get executed.

Change your logger to write to os.Stderr or something and you will see Ut oh print.