Answer the question
In order to leave comments, you need to log in
How to log an error in Go (Panic, etc.) at which the server crashes?
Hello.
If I run a goprogram from the command line - in case of some error - I see a result like
panic: runtime error: invalid memory address or nil pointer
Answer the question
In order to leave comments, you need to log in
You can also run it like this:
then both stderr and stdout will be poured into log.txt
If they are needed separately, then like this:./main 2>errors.txt >log.txt
Found a solution
For unix systems, a function is created
func redirectStderr(f *os.File) {
err := syscall.Dup2(int(f.Fd()), int(os.Stderr.Fd()))
if err != nil {
log.Fatalf("Failed to redirect stderr to file: %v", err)
}
}
redirectStderr(os.Stdout)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question