logger.go 831 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package elastic
  4. import (
  5. "fmt"
  6. "go.uber.org/zap"
  7. )
  8. var logger *zap.Logger // 日志器
  9. // SetLogger 注册日志器
  10. func SetLogger(l *zap.Logger) {
  11. logger = l
  12. }
  13. type ErrorLog struct {
  14. }
  15. func (p *ErrorLog) Printf(format string, v ...interface{}) {
  16. if logger != nil {
  17. logger.Error("elastic", zap.String("error", fmt.Sprintf(format, v...)))
  18. }
  19. }
  20. type InfoLog struct {
  21. }
  22. func (p *InfoLog) Printf(format string, v ...interface{}) {
  23. if logger != nil {
  24. logger.Info("elastic", zap.String("info", fmt.Sprintf(format, v...)))
  25. }
  26. }
  27. type TraceLog struct {
  28. }
  29. func (p *TraceLog) Printf(format string, v ...interface{}) {
  30. if logger != nil {
  31. logger.Debug("elastic", zap.String("debug", fmt.Sprintf(format, v...)))
  32. }
  33. }