diff --git a/log/helper.go b/log/helper.go index 7e6a25d12..dea23c765 100644 --- a/log/helper.go +++ b/log/helper.go @@ -3,6 +3,7 @@ package log import ( "context" "fmt" + "os" ) // Helper is a logger helper. @@ -89,3 +90,21 @@ func (h *Helper) Errorf(format string, a ...interface{}) { func (h *Helper) Errorw(keyvals ...interface{}) { h.logger.Log(LevelError, keyvals...) } + +// Fatal logs a message at fatal level. +func (h *Helper) Fatal(a ...interface{}) { + h.logger.Log(LevelFatal, "msg", fmt.Sprint(a...)) + os.Exit(1) +} + +// Fatalf logs a message at fatal level. +func (h *Helper) Fatalf(format string, a ...interface{}) { + h.logger.Log(LevelFatal, "msg", fmt.Sprintf(format, a...)) + os.Exit(1) +} + +// Fatalw logs a message at fatal level. +func (h *Helper) Fatalw(keyvals ...interface{}) { + h.logger.Log(LevelFatal, keyvals...) + os.Exit(1) +} diff --git a/log/level.go b/log/level.go index d76fc4116..2dfa4ed41 100644 --- a/log/level.go +++ b/log/level.go @@ -17,6 +17,8 @@ const ( LevelWarn // LevelError is logger error level. LevelError + // LevelFatal is logger fatal level + LevelFatal ) func (l Level) String() string { @@ -29,6 +31,8 @@ func (l Level) String() string { return "WARN" case LevelError: return "ERROR" + case LevelFatal: + return "FATAL" default: return "" } @@ -45,6 +49,8 @@ func ParseLevel(s string) Level { return LevelWarn case "ERROR": return LevelError + case "FATAL": + return LevelFatal } return LevelInfo }