github.com/songzhibin97/gkit@v1.2.13/log/helper.go (about)

     1  package log
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  )
     7  
     8  type Helper struct {
     9  	Logger
    10  }
    11  
    12  // NewHelper 实例化函数
    13  func NewHelper(log Logger) *Helper {
    14  	return &Helper{log}
    15  }
    16  
    17  // WithContext 调用 logger WithContext 刷新ctx
    18  func (h *Helper) WithContext(ctx context.Context) *Helper {
    19  	return &Helper{Logger: WithContext(ctx, h.Logger)}
    20  }
    21  
    22  // Log .
    23  func (h *Helper) Log(lever Lever, kvs ...interface{}) {
    24  	_ = h.Logger.Log(lever, kvs...)
    25  }
    26  
    27  // Debug .
    28  func (h *Helper) Debug(a ...interface{}) {
    29  	_ = h.Logger.Log(LevelDebug, "message", fmt.Sprint(a...))
    30  }
    31  
    32  // Debugf .
    33  func (h *Helper) Debugf(format string, a ...interface{}) {
    34  	h.Logger.Log(LevelDebug, "message", fmt.Sprintf(format, a...))
    35  }
    36  
    37  // Debugw .
    38  func (h *Helper) Debugw(keyvals ...interface{}) {
    39  	h.Logger.Log(LevelDebug, keyvals...)
    40  }
    41  
    42  // Info .
    43  func (h *Helper) Info(a ...interface{}) {
    44  	h.Logger.Log(LevelInfo, "message", fmt.Sprint(a...))
    45  }
    46  
    47  // Infof .
    48  func (h *Helper) Infof(format string, a ...interface{}) {
    49  	h.Logger.Log(LevelInfo, "message", fmt.Sprintf(format, a...))
    50  }
    51  
    52  // Infow .
    53  func (h *Helper) Infow(keyvals ...interface{}) {
    54  	h.Logger.Log(LevelInfo, keyvals...)
    55  }
    56  
    57  // Warn .
    58  func (h *Helper) Warn(a ...interface{}) {
    59  	h.Logger.Log(LevelWarn, "message", fmt.Sprint(a...))
    60  }
    61  
    62  // Warnf .
    63  func (h *Helper) Warnf(format string, a ...interface{}) {
    64  	h.Logger.Log(LevelWarn, "message", fmt.Sprintf(format, a...))
    65  }
    66  
    67  // Warnw .
    68  func (h *Helper) Warnw(keyvals ...interface{}) {
    69  	h.Logger.Log(LevelWarn, keyvals...)
    70  }
    71  
    72  // Error .
    73  func (h *Helper) Error(a ...interface{}) {
    74  	h.Logger.Log(LevelError, "message", fmt.Sprint(a...))
    75  }
    76  
    77  // Errorf .
    78  func (h *Helper) Errorf(format string, a ...interface{}) {
    79  	h.Logger.Log(LevelError, "message", fmt.Sprintf(format, a...))
    80  }
    81  
    82  // Errorw .
    83  func (h *Helper) Errorw(keyvals ...interface{}) {
    84  	h.Logger.Log(LevelError, keyvals...)
    85  }