Created
May 22, 2023 15:04
-
-
Save HalCanary/ea2c53c5f17896d5024776f9c88f589f to your computer and use it in GitHub Desktop.
logExample.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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