Skip to content

Instantly share code, notes, and snippets.

@HalCanary
Created May 22, 2023 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HalCanary/ea2c53c5f17896d5024776f9c88f589f to your computer and use it in GitHub Desktop.
Save HalCanary/ea2c53c5f17896d5024776f9c88f589f to your computer and use it in GitHub Desktop.
logExample.go
package main
import (
"errors"
"log"
"os"
)
func expectNil(err error) {
if err != nil {
log.Output(2, err.Error())
os.Exit(1)
}
}
func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile | log.LUTC)
expectNil(errors.New("This is a test error.")) // The log should show this line number.
}
/*
Expected Output:
2023/05/22 15:02:33 logExample.go:19: This is a test error.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment