2020-11-27 13:00:45 +00:00
|
|
|
package logger
|
|
|
|
|
|
|
|
import (
|
2021-10-13 15:05:59 +00:00
|
|
|
"fmt"
|
|
|
|
|
2020-11-27 13:00:45 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
StandardLogger Logger = &logger{FieldLogger: logrus.StandardLogger()}
|
|
|
|
)
|
|
|
|
|
|
|
|
func New() Logger {
|
|
|
|
return &logger{FieldLogger: logrus.New()}
|
|
|
|
}
|
|
|
|
|
|
|
|
type Logger interface {
|
|
|
|
WithField(key string, value interface{}) Logger
|
2021-10-13 15:05:59 +00:00
|
|
|
WithFields(kv ...interface{}) Logger
|
2020-11-27 13:00:45 +00:00
|
|
|
WithError(err error) Logger
|
|
|
|
|
|
|
|
Debugf(format string, args ...interface{})
|
|
|
|
Infof(format string, args ...interface{})
|
|
|
|
Printf(format string, args ...interface{})
|
|
|
|
Warnf(format string, args ...interface{})
|
|
|
|
Warningf(format string, args ...interface{})
|
|
|
|
Errorf(format string, args ...interface{})
|
|
|
|
Fatalf(format string, args ...interface{})
|
|
|
|
Panicf(format string, args ...interface{})
|
|
|
|
|
|
|
|
Debug(args ...interface{})
|
|
|
|
Info(args ...interface{})
|
|
|
|
Print(args ...interface{})
|
|
|
|
Warn(args ...interface{})
|
|
|
|
Warning(args ...interface{})
|
|
|
|
Error(args ...interface{})
|
|
|
|
Fatal(args ...interface{})
|
|
|
|
Panic(args ...interface{})
|
|
|
|
|
|
|
|
Debugln(args ...interface{})
|
|
|
|
Infoln(args ...interface{})
|
|
|
|
Println(args ...interface{})
|
|
|
|
Warnln(args ...interface{})
|
|
|
|
Warningln(args ...interface{})
|
|
|
|
Errorln(args ...interface{})
|
|
|
|
Fatalln(args ...interface{})
|
|
|
|
Panicln(args ...interface{})
|
|
|
|
}
|
|
|
|
|
|
|
|
type logger struct {
|
|
|
|
logrus.FieldLogger
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *logger) WithField(key string, value interface{}) Logger {
|
|
|
|
return &logger{FieldLogger: l.FieldLogger.WithField(key, value)}
|
|
|
|
}
|
|
|
|
|
2021-10-13 15:05:59 +00:00
|
|
|
func (l *logger) WithFields(kv ...interface{}) Logger {
|
2021-09-17 23:39:15 +00:00
|
|
|
for i := 0; i < len(kv); i += 2 {
|
2021-10-13 15:05:59 +00:00
|
|
|
l.FieldLogger = l.FieldLogger.WithField(fmt.Sprintf("%v", kv[i]), kv[i+1])
|
2020-11-27 13:00:45 +00:00
|
|
|
}
|
|
|
|
return l
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *logger) WithError(err error) Logger {
|
|
|
|
return &logger{FieldLogger: l.FieldLogger.WithError(err)}
|
|
|
|
}
|