photoprism/internal/server/logger.go
Michael Mayer e739dd3e89 Auth: Add support for config and routing extensions (WIP) #782 #2478
Enables developers to extend the existing config and API. Initial proof
of concept and work in progress. Implementation details may change.
Feedback welcome!

Signed-off-by: Michael Mayer <michael@photoprism.app>
2022-07-05 23:13:34 +02:00

42 lines
725 B
Go

package server
import (
"time"
"github.com/gin-gonic/gin"
"github.com/photoprism/photoprism/pkg/clean"
)
// 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.
log.Debugf("server: %s %s (%3d) [%v]",
method,
clean.Log(path),
statusCode,
latency,
)
}
}