photoprism/internal/server/logger.go

41 lines
666 B
Go
Raw Normal View History

package server
import (
"time"
"github.com/gin-gonic/gin"
)
// 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)
// clientIP := c.ClientIP()
method := c.Request.Method
statusCode := c.Writer.Status()
if raw != "" {
path = path + "?" + raw
}
// Use debug level to keep production logs clean.
2021-01-10 15:28:42 +01:00
log.Debugf("http: %s %s (%3d) [%v]",
method,
path,
statusCode,
latency,
)
}
}