logger.go 671 B

1234567891011121314151617181920212223242526272829303132
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package handle
  4. import (
  5. "fmt"
  6. "go.uber.org/zap"
  7. "time"
  8. )
  9. var l *zap.Logger
  10. var accessLog *zap.Logger
  11. func SetLogger(logger *zap.Logger) {
  12. l = logger
  13. }
  14. func SetAccessLogger(logger *zap.Logger){
  15. accessLog = logger
  16. }
  17. func printAccessLog(msgType string,startTime uint64, status string) {
  18. // TODO 添加追踪
  19. if accessLog != nil {
  20. endTime := uint64(time.Now().UnixNano())
  21. accessLog.Info("ods",
  22. zap.String("msg_type", msgType),
  23. zap.String("status", status),
  24. zap.String("elapsed", fmt.Sprintf("%fms", float64(endTime-startTime)/1000000)))
  25. }
  26. }