logger.go 729 B

12345678910111213141516171819202122232425262728293031
  1. // Copyright 2019 autocareai.com. All rights reserved.
  2. // Use of this source code is governed by autocareai.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,sourceCode string ,startTime uint64, status string) {
  18. // TODO 添加追踪
  19. if accessLog != nil {
  20. endTime := uint64(time.Now().UnixNano())
  21. accessLog.Info("dws",
  22. zap.String("msg_type", msgType),
  23. zap.String("source_code", sourceCode),
  24. zap.String("status", status),
  25. zap.String("elapsed", fmt.Sprintf("%fms", float64(endTime-startTime)/1000000)))
  26. }
  27. }