Add log level helper funtions (#1229)

This commit is contained in:
Asim Aslam 2020-02-21 08:43:23 +00:00 committed by GitHub
parent ee977acfef
commit 116855572b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 4 deletions

View File

@ -68,3 +68,51 @@ func GetLevel(levelStr string) (Level, error) {
} }
return InfoLevel, fmt.Errorf("Unknown Level String: '%s', defaulting to NoLevel", levelStr) return InfoLevel, fmt.Errorf("Unknown Level String: '%s', defaulting to NoLevel", levelStr)
} }
func Info(args ...interface{}) {
DefaultLogger.Log(InfoLevel, args...)
}
func Infof(template string, args ...interface{}) {
DefaultLogger.Logf(InfoLevel, template, args...)
}
func Trace(args ...interface{}) {
DefaultLogger.Log(TraceLevel, args...)
}
func Tracef(template string, args ...interface{}) {
DefaultLogger.Logf(TraceLevel, template, args...)
}
func Debug(args ...interface{}) {
DefaultLogger.Log(DebugLevel, args...)
}
func Debugf(template string, args ...interface{}) {
DefaultLogger.Logf(DebugLevel, template, args...)
}
func Warn(args ...interface{}) {
DefaultLogger.Log(WarnLevel, args...)
}
func Warnf(template string, args ...interface{}) {
DefaultLogger.Logf(WarnLevel, template, args...)
}
func Error(args ...interface{}) {
DefaultLogger.Log(ErrorLevel, args...)
}
func Errorf(template string, args ...interface{}) {
DefaultLogger.Logf(ErrorLevel, template, args...)
}
func Fatal(args ...interface{}) {
DefaultLogger.Log(FatalLevel, args...)
}
func Fatalf(template string, args ...interface{}) {
DefaultLogger.Logf(FatalLevel, template, args...)
}

View File

@ -28,10 +28,6 @@ func Init(opts ...Option) error {
return DefaultLogger.Init(opts...) return DefaultLogger.Init(opts...)
} }
func Error(err error) Logger {
return DefaultLogger.Error(err)
}
func Fields(fields map[string]interface{}) Logger { func Fields(fields map[string]interface{}) Logger {
return DefaultLogger.Fields(fields) return DefaultLogger.Fields(fields)
} }
@ -47,3 +43,7 @@ func Logf(level Level, format string, v ...interface{}) {
func String() string { func String() string {
return DefaultLogger.String() return DefaultLogger.String()
} }
func WithError(err error) Logger {
return DefaultLogger.Error(err)
}