mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-29 22:26:15 -06:00
set logger
This commit is contained in:
parent
cf6d2beb82
commit
d58c2b7b0d
2 changed files with 15 additions and 28 deletions
|
|
@ -19,7 +19,6 @@
|
|||
package router
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
|
|
@ -31,8 +30,7 @@ var skipPaths = map[string]interface{}{
|
|||
"/api/v1/streaming": nil,
|
||||
}
|
||||
|
||||
// LoggerWithConfig instance a Logger middleware with config.
|
||||
func LoggerWithConfig(log *logrus.Logger) gin.HandlerFunc {
|
||||
func loggerWithConfig(log *logrus.Logger) gin.HandlerFunc {
|
||||
logHandler := func(c *gin.Context) {
|
||||
start := time.Now()
|
||||
path := c.Request.URL.Path
|
||||
|
|
@ -54,12 +52,21 @@ func LoggerWithConfig(log *logrus.Logger) gin.HandlerFunc {
|
|||
}
|
||||
|
||||
l := log.WithFields(logrus.Fields{
|
||||
"latency": fmt.Sprintf("%13v", latency),
|
||||
"latency": latency,
|
||||
"clientIP": clientIP,
|
||||
"method": method,
|
||||
"statusCode": statusCode,
|
||||
"path": path,
|
||||
})
|
||||
|
||||
http.StatusText(statusCode)
|
||||
if errorMessage != "" {
|
||||
l.Error(errorMessage)
|
||||
return
|
||||
}
|
||||
|
||||
l.Infof("%s: wrote %d bytes in %v", http.StatusText(statusCode), bodySize, latency)
|
||||
}
|
||||
}
|
||||
|
||||
return logHandler
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue