2020-02-29 02:31:59 +02:00
|
|
|
package logger
|
|
|
|
|
|
|
|
type Helper struct {
|
|
|
|
Logger
|
2020-03-03 10:07:38 +02:00
|
|
|
fields map[string]interface{}
|
2020-02-29 02:31:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewHelper(log Logger) *Helper {
|
2020-03-03 10:07:38 +02:00
|
|
|
return &Helper{Logger: log}
|
2020-02-29 02:31:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Helper) Info(args ...interface{}) {
|
2020-03-03 10:07:38 +02:00
|
|
|
h.Logger.Fields(h.fields).Log(InfoLevel, args...)
|
2020-02-29 02:31:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Helper) Infof(template string, args ...interface{}) {
|
2020-03-03 10:07:38 +02:00
|
|
|
h.Logger.Fields(h.fields).Logf(InfoLevel, template, args...)
|
2020-02-29 02:31:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Helper) Trace(args ...interface{}) {
|
2020-03-03 10:07:38 +02:00
|
|
|
h.Logger.Fields(h.fields).Log(TraceLevel, args...)
|
2020-02-29 02:31:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Helper) Tracef(template string, args ...interface{}) {
|
2020-03-03 10:07:38 +02:00
|
|
|
h.Logger.Fields(h.fields).Logf(TraceLevel, template, args...)
|
2020-02-29 02:31:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Helper) Debug(args ...interface{}) {
|
2020-03-03 10:07:38 +02:00
|
|
|
h.Logger.Fields(h.fields).Log(DebugLevel, args...)
|
2020-02-29 02:31:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Helper) Debugf(template string, args ...interface{}) {
|
2020-03-03 10:07:38 +02:00
|
|
|
h.Logger.Fields(h.fields).Logf(DebugLevel, template, args...)
|
2020-02-29 02:31:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Helper) Warn(args ...interface{}) {
|
2020-03-03 10:07:38 +02:00
|
|
|
h.Logger.Fields(h.fields).Log(WarnLevel, args...)
|
2020-02-29 02:31:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Helper) Warnf(template string, args ...interface{}) {
|
2020-03-03 10:07:38 +02:00
|
|
|
h.Logger.Fields(h.fields).Logf(WarnLevel, template, args...)
|
2020-02-29 02:31:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Helper) Error(args ...interface{}) {
|
2020-03-03 10:07:38 +02:00
|
|
|
h.Logger.Fields(h.fields).Log(ErrorLevel, args...)
|
2020-02-29 02:31:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Helper) Errorf(template string, args ...interface{}) {
|
2020-03-03 10:07:38 +02:00
|
|
|
h.Logger.Fields(h.fields).Logf(ErrorLevel, template, args...)
|
2020-02-29 02:31:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Helper) Fatal(args ...interface{}) {
|
2020-03-03 10:07:38 +02:00
|
|
|
h.Logger.Fields(h.fields).Log(ErrorLevel, args...)
|
2020-02-29 02:31:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Helper) Fatalf(template string, args ...interface{}) {
|
2020-03-03 10:07:38 +02:00
|
|
|
h.Logger.Fields(h.fields).Logf(ErrorLevel, template, args...)
|
2020-02-29 02:31:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Helper) WithError(err error) *Helper {
|
2020-03-03 10:07:38 +02:00
|
|
|
fields := copyFields(h.fields)
|
|
|
|
fields["error"] = err
|
|
|
|
return &Helper{Logger: h.Logger, fields: fields}
|
2020-02-29 02:31:59 +02:00
|
|
|
}
|
2020-02-29 02:39:41 +02:00
|
|
|
|
|
|
|
func (h *Helper) WithFields(fields map[string]interface{}) *Helper {
|
2020-03-03 10:07:38 +02:00
|
|
|
nfields := copyFields(fields)
|
|
|
|
for k, v := range h.fields {
|
|
|
|
nfields[k] = v
|
|
|
|
}
|
|
|
|
return &Helper{Logger: h.Logger, fields: nfields}
|
2020-02-29 02:39:41 +02:00
|
|
|
}
|