Add Must() function in log
@@ -87,6 +87,7 @@ var systemFields = map[string]bool{
var Trace, Print, Debug, Info, Warn, Error, Panic, Fatal func(args ...interface{})
var Tracef, Printf, Debugf, Infof, Warnf, Errorf, Panicf, Fatalf func(format string, args ...interface{})
var Traceln, Println, Debugln, Infoln, Warnln, Errorln, Panicln, Fatalln func(args ...interface{})
+var Must func(err error)
type Fields logrus.Fields
@@ -127,6 +128,8 @@ type Logger interface {
Logf(level Level, format string, args ...interface{})
Logln(level Level, args ...interface{})
+ Must(err error)
+
WithFields(Fields) Logger
SetReportCaller(yn bool)
SetLevel(lv Level)
@@ -146,6 +149,12 @@ type entryWrapper struct {
*logrus.Entry
}
+func (w entryWrapper) Must(err error) {
+ if err != nil {
+ w.Panicf("%+v", err)
+ }
+}
+
func (w entryWrapper) addHook(hook logrus.Hook) {
w.Logger.AddHook(hook)
}
@@ -222,6 +231,12 @@ func (w loggerWrapper) WithFields(fields Fields) Logger {
}
}
+func (w loggerWrapper) Must(err error) {
+ if err != nil {
+ w.Panicf("%+v", err)
+ }
+}
+
func (w loggerWrapper) SetLevel(lv Level) {
w.Logger.SetLevel(logrus.Level(lv))
}
@@ -319,6 +334,8 @@ func SetGlobalLogger(logger Logger) {
Fatal = logger.Fatal
Fatalf = logger.Fatalf
Fatalln = logger.Fatalln
+
+ Must = logger.Must
}
func WithFields(fields Fields) Logger {
