mirror of
https://github.com/go-kratos/kratos.git
synced 2025-01-10 00:29:01 +02:00
49 lines
925 B
Go
49 lines
925 B
Go
package log
|
|
|
|
var (
|
|
// DefaultLogger is default logger.
|
|
DefaultLogger Logger = NewStdLogger()
|
|
)
|
|
|
|
// Logger is a logger interface.
|
|
type Logger interface {
|
|
Print(pairs ...interface{})
|
|
}
|
|
|
|
type logger struct {
|
|
log Logger
|
|
pairs []interface{}
|
|
}
|
|
|
|
func (l *logger) Print(pairs ...interface{}) {
|
|
l.log.Print(append(pairs, l.pairs...)...)
|
|
}
|
|
|
|
// With with logger kv pairs.
|
|
func With(log Logger, pairs ...interface{}) Logger {
|
|
if len(pairs) == 0 {
|
|
return log
|
|
}
|
|
return &logger{log: log, pairs: pairs}
|
|
}
|
|
|
|
// Debug returns a debug logger.
|
|
func Debug(log Logger) Logger {
|
|
return With(log, LevelKey, LevelDebug)
|
|
}
|
|
|
|
// Info returns a info logger.
|
|
func Info(log Logger) Logger {
|
|
return With(log, LevelKey, LevelInfo)
|
|
}
|
|
|
|
// Warn return a warn logger.
|
|
func Warn(log Logger) Logger {
|
|
return With(log, LevelKey, LevelWarn)
|
|
}
|
|
|
|
// Error returns a error logger.
|
|
func Error(log Logger) Logger {
|
|
return With(log, LevelKey, LevelError)
|
|
}
|