You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
947 B
50 lines
947 B
package log
|
|
|
|
import "os"
|
|
|
|
var (
|
|
// DefaultLogger is default logger.
|
|
DefaultLogger Logger = NewStdLogger(os.Stderr)
|
|
)
|
|
|
|
// 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)
|
|
}
|
|
|