问题描述
使用 log.Println
登录Go时,我经常得到
When logging in Go with log.Println
, I frequently get
2012/05/13 16:45:50 evaluating %v(PANIC=3)
我不确定如何确定做错了什么,我假设某个地方 fmt.Println
遇到了由我自己的 Stringer
产生的恐慌接口实现,以免由于记录失败而使我的程序崩溃.
I'm not sure how to determine what I've done wrong, I assume that somewhere fmt.Println
has caught a panic generated by one of my own Stringer
interface implementations, so as not to crash my program due to logging failure.
我如何确定正在发生的事情?为什么会收到此错误消息?
How do I work out what's going on? Why am I getting this erroneous message?
推荐答案
是的,在 String
方法中出现了恐慌.但这与 log
包无关. Println
使用%v
,而%v
表示正在运行 String
方法.在 String
方法中出现恐慌会调用 catchPanic
.在您的输出中, 3
是您的恐慌值.
You are right, there is a panic in a String
method. But it has nothing to do with the log
package. Println
uses %v
, and %v
means running String
method. Having a panic in the String
method invokes catchPanic
. Here in your output 3
is the value of your panic.
这篇关于使用Go的日志包以默认格式设置PANIC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!