How do you get a Golang program to print the line number of the error it just called?

后端 未结 3 510
南方客
南方客 2020-12-12 12:40

I was trying to throw errors in my Golang program with log.Fatal but, log.Fatal does not also print the line where the log.Fatal was r

3条回答
  •  粉色の甜心
    2020-12-12 13:17

    You can set the Flags on either a custom Logger, or the default to include Llongfile or Lshortfile

    // to change the flags on the default logger
    log.SetFlags(log.LstdFlags | log.Lshortfile)
    

提交回复
热议问题