Reputation: 283
I installed golang on a redhat server through epel. I'm trying to analyze the panic logs but I can't find where the logs are stored. Any hint ? There is no trace in /var/log
func main() {
http.HandleFunc("/", panicRecover(test))
log.Fatal(http.ListenAndServe(":80", nil))
}
func test(){
out, err := exec.Command("echo ", "something").Output()
if err != nil {
log.Panic(err)
}
}
func panicRecover(f func(w http.ResponseWriter, r *http.Request)) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
defer func() {
if r := recover(); r != nil {
log.Printf("PANIC RECOVERED:%s\n", r)
}
}()
f(w, r)
}
Upvotes: 3
Views: 13650
Reputation: 166559
To stderr
.
For example,
package main
import "log"
func main() {
log.Panic("log.Panic to stderr")
}
$ go run panic.go 2>stderr.txt
stderr.txt
File:
2014/06/09 00:30:54 log.Panic to stderr
panic: log.Panic to stderr
goroutine 16 [running]:
runtime.panic(0x497180, 0xc2080001a0)
/home/peter/go/src/pkg/runtime/panic.c:279 +0xf5
log.Panic(0x7f88770fff20, 0x1, 0x1)
/home/peter/go/src/pkg/log/log.go:307 +0xb6
main.main()
/home/peter/gopath/src/so/panic.go:6 +0xa7
goroutine 17 [runnable]:
runtime.MHeap_Scavenger()
/home/peter/go/src/pkg/runtime/mheap.c:507
runtime.goexit()
/home/peter/go/src/pkg/runtime/proc.c:1445
goroutine 18 [runnable]:
bgsweep()
/home/peter/go/src/pkg/runtime/mgc0.c:1976
runtime.goexit()
/home/peter/go/src/pkg/runtime/proc.c:1445
goroutine 19 [runnable]:
runfinq()
/home/peter/go/src/pkg/runtime/mgc0.c:2606
runtime.goexit()
/home/peter/go/src/pkg/runtime/proc.c:1445
exit status 2
Upvotes: 8