From 509d727fba52a8bf849bfd9bd3ee47a519f71ffc Mon Sep 17 00:00:00 2001 From: Olivier Poitrey Date: Fri, 19 Apr 2019 15:24:32 -0700 Subject: [PATCH] Add the Err function to ease the log errors. --- log.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/log.go b/log.go index 5508d5a..846b9ca 100644 --- a/log.go +++ b/log.go @@ -291,6 +291,18 @@ func (l *Logger) Error() *Event { return l.newEvent(ErrorLevel, nil) } +// Err starts a new message with error level with err as a field if not nil or +// with info level if err is nil. +// +// You must call Msg on the returned event in order to send the event. +func (l *Logger) Err(err error) *Event { + if err != nil { + return l.Error().Err(err) + } else { + return l.Info() + } +} + // Fatal starts a new message with fatal level. The os.Exit(1) function // is called by the Msg method, which terminates the program immediately. //