access.go 708 B

12345678910111213141516171819202122232425
  1. package task
  2. import (
  3. "fmt"
  4. "time"
  5. "gd_gateway/common.in/span"
  6. "github.com/astaxie/beego/context"
  7. "go.uber.org/zap"
  8. )
  9. func printAccessLog(ctx *context.Context, startTime uint64, status string, spanID span.SpanID) {
  10. if l != nil {
  11. endTime := uint64(time.Now().UnixNano())
  12. l.Info(ctx.Input.Method(),
  13. zap.Uint64("trace_id", uint64(spanID.Trace)),
  14. zap.Uint64("span_id", uint64(spanID.Span)),
  15. zap.Uint64("parent_id", uint64(spanID.Parent)),
  16. zap.String("status", status),
  17. zap.String("elapsed", fmt.Sprintf("%fms", float64(endTime-startTime)/1000000)),
  18. zap.String("ip", ctx.Input.IP()),
  19. zap.String("uri", ctx.Input.URI()),
  20. zap.String("body", string(ctx.Input.RequestBody)))
  21. }
  22. }