| 10 | ) |
| 11 | |
| 12 | func GinzapWithConfig() func(c *gin.Context) { |
| 13 | return func(c *gin.Context) { |
| 14 | ginzap.GinzapWithConfig(common.LoggerZap, &ginzap.Config{ |
| 15 | UTC: true, |
| 16 | TimeFormat: time.RFC3339, |
| 17 | Context: ginzap.Fn(func(c *gin.Context) []zapcore.Field { |
| 18 | fields := []zapcore.Field{} |
| 19 | // log request ID |
| 20 | if requestID := c.Writer.Header().Get(RequestIdKey); requestID != "" { |
| 21 | fields = append(fields, zap.String("request_id", requestID)) |
| 22 | } |
| 23 | |
| 24 | // log trace and span ID |
| 25 | /*if trace.SpanFromContext(c.Request.Context()).SpanContext().IsValid() { |
| 26 | fields = append(fields, zap.String("trace_id", trace.SpanFromContext(c.Request.Context()).SpanContext().TraceID().String())) |
| 27 | fields = append(fields, zap.String("span_id", trace.SpanFromContext(c.Request.Context()).SpanContext().SpanID().String())) |
| 28 | }*/ |
| 29 | |
| 30 | // log request body |
| 31 | /*var body []byte |
| 32 | var buf bytes.Buffer |
| 33 | tee := io.TeeReader(c.Request.Body, &buf) |
| 34 | body, _ = io.ReadAll(tee) |
| 35 | c.Request.Body = io.NopCloser(&buf) |
| 36 | fields = append(fields, zap.String("body", string(body)))*/ |
| 37 | |
| 38 | return fields |
| 39 | }), |
| 40 | }) |
| 41 | } |
| 42 | } |