fix(log): call depth (#1885)

* fix log caller
pull/1887/head
Tony Chen 3 years ago committed by GitHub
parent d373c51acf
commit 51fb0e0440
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 32
      log/helper.go

@ -6,6 +6,7 @@ import (
"os" "os"
) )
// DefaultMessageKey default message key.
var DefaultMessageKey = "msg" var DefaultMessageKey = "msg"
// Option is Helper option. // Option is Helper option.
@ -17,6 +18,7 @@ type Helper struct {
msgKey string msgKey string
} }
// WithMessageKey with message key.
func WithMessageKey(k string) Option { func WithMessageKey(k string) Option {
return func(opts *Helper) { return func(opts *Helper) {
opts.msgKey = k opts.msgKey = k
@ -51,78 +53,78 @@ func (h *Helper) Log(level Level, keyvals ...interface{}) {
// Debug logs a message at debug level. // Debug logs a message at debug level.
func (h *Helper) Debug(a ...interface{}) { func (h *Helper) Debug(a ...interface{}) {
h.Log(LevelDebug, h.msgKey, fmt.Sprint(a...)) _ = h.logger.Log(LevelDebug, h.msgKey, fmt.Sprint(a...))
} }
// Debugf logs a message at debug level. // Debugf logs a message at debug level.
func (h *Helper) Debugf(format string, a ...interface{}) { func (h *Helper) Debugf(format string, a ...interface{}) {
h.Log(LevelDebug, h.msgKey, fmt.Sprintf(format, a...)) _ = h.logger.Log(LevelDebug, h.msgKey, fmt.Sprintf(format, a...))
} }
// Debugw logs a message at debug level. // Debugw logs a message at debug level.
func (h *Helper) Debugw(keyvals ...interface{}) { func (h *Helper) Debugw(keyvals ...interface{}) {
h.Log(LevelDebug, keyvals...) _ = h.logger.Log(LevelDebug, keyvals...)
} }
// Info logs a message at info level. // Info logs a message at info level.
func (h *Helper) Info(a ...interface{}) { func (h *Helper) Info(a ...interface{}) {
h.Log(LevelInfo, h.msgKey, fmt.Sprint(a...)) _ = h.logger.Log(LevelInfo, h.msgKey, fmt.Sprint(a...))
} }
// Infof logs a message at info level. // Infof logs a message at info level.
func (h *Helper) Infof(format string, a ...interface{}) { func (h *Helper) Infof(format string, a ...interface{}) {
h.Log(LevelInfo, h.msgKey, fmt.Sprintf(format, a...)) _ = h.logger.Log(LevelInfo, h.msgKey, fmt.Sprintf(format, a...))
} }
// Infow logs a message at info level. // Infow logs a message at info level.
func (h *Helper) Infow(keyvals ...interface{}) { func (h *Helper) Infow(keyvals ...interface{}) {
h.Log(LevelInfo, keyvals...) _ = h.logger.Log(LevelInfo, keyvals...)
} }
// Warn logs a message at warn level. // Warn logs a message at warn level.
func (h *Helper) Warn(a ...interface{}) { func (h *Helper) Warn(a ...interface{}) {
h.Log(LevelWarn, h.msgKey, fmt.Sprint(a...)) _ = h.logger.Log(LevelWarn, h.msgKey, fmt.Sprint(a...))
} }
// Warnf logs a message at warnf level. // Warnf logs a message at warnf level.
func (h *Helper) Warnf(format string, a ...interface{}) { func (h *Helper) Warnf(format string, a ...interface{}) {
h.Log(LevelWarn, h.msgKey, fmt.Sprintf(format, a...)) _ = h.logger.Log(LevelWarn, h.msgKey, fmt.Sprintf(format, a...))
} }
// Warnw logs a message at warnf level. // Warnw logs a message at warnf level.
func (h *Helper) Warnw(keyvals ...interface{}) { func (h *Helper) Warnw(keyvals ...interface{}) {
h.Log(LevelWarn, keyvals...) _ = h.logger.Log(LevelWarn, keyvals...)
} }
// Error logs a message at error level. // Error logs a message at error level.
func (h *Helper) Error(a ...interface{}) { func (h *Helper) Error(a ...interface{}) {
h.Log(LevelError, h.msgKey, fmt.Sprint(a...)) _ = h.logger.Log(LevelError, h.msgKey, fmt.Sprint(a...))
} }
// Errorf logs a message at error level. // Errorf logs a message at error level.
func (h *Helper) Errorf(format string, a ...interface{}) { func (h *Helper) Errorf(format string, a ...interface{}) {
h.Log(LevelError, h.msgKey, fmt.Sprintf(format, a...)) _ = h.logger.Log(LevelError, h.msgKey, fmt.Sprintf(format, a...))
} }
// Errorw logs a message at error level. // Errorw logs a message at error level.
func (h *Helper) Errorw(keyvals ...interface{}) { func (h *Helper) Errorw(keyvals ...interface{}) {
h.Log(LevelError, keyvals...) _ = h.logger.Log(LevelError, keyvals...)
} }
// Fatal logs a message at fatal level. // Fatal logs a message at fatal level.
func (h *Helper) Fatal(a ...interface{}) { func (h *Helper) Fatal(a ...interface{}) {
h.Log(LevelFatal, h.msgKey, fmt.Sprint(a...)) _ = h.logger.Log(LevelFatal, h.msgKey, fmt.Sprint(a...))
os.Exit(1) os.Exit(1)
} }
// Fatalf logs a message at fatal level. // Fatalf logs a message at fatal level.
func (h *Helper) Fatalf(format string, a ...interface{}) { func (h *Helper) Fatalf(format string, a ...interface{}) {
h.Log(LevelFatal, h.msgKey, fmt.Sprintf(format, a...)) _ = h.logger.Log(LevelFatal, h.msgKey, fmt.Sprintf(format, a...))
os.Exit(1) os.Exit(1)
} }
// Fatalw logs a message at fatal level. // Fatalw logs a message at fatal level.
func (h *Helper) Fatalw(keyvals ...interface{}) { func (h *Helper) Fatalw(keyvals ...interface{}) {
h.Log(LevelFatal, keyvals...) _ = h.logger.Log(LevelFatal, keyvals...)
os.Exit(1) os.Exit(1)
} }

Loading…
Cancel
Save