Files
2025-11-21 16:32:35 +08:00

26 lines
397 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package recovery
import (
"runtime/debug"
"go.uber.org/zap"
)
var logger *zap.Logger
func Init() {
// 初始化logger这里简化处理实际应该从外部传入
logger, _ = zap.NewProduction()
}
// Recover 恢复panic
func Recover() {
if r := recover(); r != nil {
logger.Error("发生panic",
zap.Any("panic", r),
zap.String("stack", string(debug.Stack())),
)
}
}