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.
kratos/log/helper.go

85 lines
1.8 KiB

4 years ago
package log
import (
"fmt"
)
// Helper is a logger helper.
type Helper struct {
debug Logger
info Logger
warn Logger
err Logger
}
// NewHelper new a logger helper.
func NewHelper(name string, logger Logger) *Helper {
logger = With(logger, "module", name)
4 years ago
return &Helper{
debug: Debug(logger),
info: Info(logger),
warn: Warn(logger),
err: Error(logger),
4 years ago
}
}
// Debug logs a message at debug level.
func (h *Helper) Debug(a ...interface{}) {
h.debug.Log("msg", fmt.Sprint(a...))
4 years ago
}
// Debugf logs a message at debug level.
func (h *Helper) Debugf(format string, a ...interface{}) {
h.debug.Log("msg", fmt.Sprintf(format, a...))
4 years ago
}
// Debugw logs a message at debug level.
func (h *Helper) Debugw(kv ...interface{}) {
h.debug.Log(kv...)
4 years ago
}
// Info logs a message at info level.
func (h *Helper) Info(a ...interface{}) {
h.info.Log("msg", fmt.Sprint(a...))
4 years ago
}
// Infof logs a message at info level.
func (h *Helper) Infof(format string, a ...interface{}) {
h.info.Log("msg", fmt.Sprintf(format, a...))
4 years ago
}
// Infow logs a message at info level.
func (h *Helper) Infow(kv ...interface{}) {
h.info.Log(kv...)
4 years ago
}
// Warn logs a message at warn level.
func (h *Helper) Warn(a ...interface{}) {
h.warn.Log("msg", fmt.Sprint(a...))
4 years ago
}
// Warnf logs a message at warnf level.
func (h *Helper) Warnf(format string, a ...interface{}) {
h.warn.Log("msg", fmt.Sprintf(format, a...))
4 years ago
}
// Warnw logs a message at warnf level.
func (h *Helper) Warnw(kv ...interface{}) {
h.warn.Log(kv...)
4 years ago
}
// Error logs a message at error level.
func (h *Helper) Error(a ...interface{}) {
h.err.Log("msg", fmt.Sprint(a...))
4 years ago
}
// Errorf logs a message at error level.
func (h *Helper) Errorf(format string, a ...interface{}) {
h.err.Log("msg", fmt.Sprintf(format, a...))
4 years ago
}
// Errorw logs a message at error level.
func (h *Helper) Errorw(kv ...interface{}) {
h.err.Log(kv...)
4 years ago
}