英文:
where does go write panic logs?
问题
我通过epel在redhat服务器上安装了golang。我正在尝试分析panic日志,但是找不到日志存储的位置。有什么提示吗?/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)
}
}
以上是你提供的代码。
英文:
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)
}
答案1
得分: 8
stderr
。
例如,
package main
import "log"
func main() {
log.Panic("log.Panic to stderr")
}
$ go run panic.go 2>stderr.txt
stderr.txt
文件:
<!-- language: none -->
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
英文:
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:
<!-- language: none -->
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论