You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/11/04 08:39:21 UTC

[GitHub] [apisix-dashboard] nic-chen commented on a change in pull request #689: chore: refactor error log for `manager api`

nic-chen commented on a change in pull request #689:
URL: https://github.com/apache/apisix-dashboard/pull/689#discussion_r517175722



##########
File path: api/filter/logging.go
##########
@@ -18,65 +18,61 @@ package filter
 
 import (
 	"bytes"
-	"io/ioutil"
-	"time"
 
 	"github.com/gin-gonic/gin"
-	"github.com/shiningrush/droplet/log"
-	"github.com/sirupsen/logrus"
 )
 
-func RequestLogHandler() gin.HandlerFunc {
-	return func(c *gin.Context) {
-		start, host, remoteIP, path, method := time.Now(), c.Request.Host, c.ClientIP(), c.Request.URL.Path, c.Request.Method
-		var val interface{}
-		if method == "GET" {
-			val = c.Request.URL.Query()
-		} else {
-			val, _ = c.GetRawData()
-
-			// set RequestBody back
-			c.Request.Body = ioutil.NopCloser(bytes.NewReader(val.([]byte)))
-		}
-		c.Set("requestBody", val)
-		uuid, _ := c.Get("X-Request-Id")
-
-		param, _ := c.Get("requestBody")
-
-		switch paramType := param.(type) {
-		case []byte:
-			param = string(param.([]byte))
-			log.Infof("type of param: %#v", paramType)
-		default:
-		}
-
-		blw := &bodyLogWriter{body: bytes.NewBufferString(""), ResponseWriter: c.Writer}
-		c.Writer = blw
-		c.Next()
-		latency := time.Since(start) / 1000000
-		statusCode := c.Writer.Status()
-		respBody := blw.body.String()
-		if uuid == "" {
-			uuid = c.Writer.Header().Get("X-Request-Id")
-		}
-		var errs []string
-		for _, err := range c.Errors {
-			errs = append(errs, err.Error())
-		}
-		logger.WithFields(logrus.Fields{
-			"requestId":  uuid,
-			"latency":    latency,
-			"remoteIp":   remoteIP,
-			"method":     method,
-			"path":       path,
-			"statusCode": statusCode,
-			"host":       host,
-			"params":     param,
-			"respBody":   respBody,
-			"errMsg":     errs,
-		}).Info("")
-	}
-}
+//func RequestLogHandler() gin.HandlerFunc {

Review comment:
       It's for access log. It doesn't work now. we could remove it first, and refactor it in a new pr.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org