2020-01-21 15:12:26 +01:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
2022-10-11 22:44:11 +02:00
|
|
|
|
2022-04-15 09:42:07 +02:00
|
|
|
"github.com/photoprism/photoprism/pkg/clean"
|
2020-01-21 15:12:26 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Logger instances a Logger middleware for Gin.
|
|
|
|
func Logger() gin.HandlerFunc {
|
|
|
|
return func(c *gin.Context) {
|
|
|
|
// Start timer
|
|
|
|
start := time.Now()
|
|
|
|
path := c.Request.URL.Path
|
|
|
|
raw := c.Request.URL.RawQuery
|
|
|
|
|
|
|
|
// Process request
|
|
|
|
c.Next()
|
|
|
|
|
|
|
|
// Stop timer
|
|
|
|
end := time.Now()
|
|
|
|
latency := end.Sub(start)
|
|
|
|
|
2022-10-11 22:44:11 +02:00
|
|
|
// clientIp := c.ClientIP()
|
2020-01-21 15:12:26 +01:00
|
|
|
method := c.Request.Method
|
|
|
|
statusCode := c.Writer.Status()
|
|
|
|
|
|
|
|
if raw != "" {
|
|
|
|
path = path + "?" + raw
|
|
|
|
}
|
|
|
|
|
2020-07-14 11:48:59 +02:00
|
|
|
// Use debug level to keep production logs clean.
|
2022-07-05 23:13:34 +02:00
|
|
|
log.Debugf("server: %s %s (%3d) [%v]",
|
2020-07-14 11:48:59 +02:00
|
|
|
method,
|
2022-04-15 09:42:07 +02:00
|
|
|
clean.Log(path),
|
2020-07-14 11:48:59 +02:00
|
|
|
statusCode,
|
|
|
|
latency,
|
|
|
|
)
|
2020-01-21 15:12:26 +01:00
|
|
|
}
|
|
|
|
}
|