access.go 633 B

12345678910111213141516171819202122232425
  1. package task
  2. import (
  3. "context"
  4. "fmt"
  5. "time"
  6. "gd_vehicle/common.in/utils"
  7. "go.uber.org/zap"
  8. )
  9. func printAccessLog(ctx context.Context, startTime uint64, status string) {
  10. if l != nil {
  11. // 取出跟踪日志id息
  12. spanID := utils.GetSpanFromRpcCtx(ctx)
  13. // 结束时间
  14. endTime := uint64(time.Now().UnixNano())
  15. l.Info(utils.GetMethodFromRpcCtx(ctx),
  16. zap.Uint64("trace_id", uint64(spanID.Trace)),
  17. zap.Uint64("span_id", uint64(spanID.Span)),
  18. zap.Uint64("parent_id", uint64(spanID.Parent)),
  19. zap.String("status", status),
  20. zap.String("elapsed", fmt.Sprintf("%fms", float64(endTime-startTime)/1000000)))
  21. }
  22. }