Simple MJPEG streamer for ESPHome cameras.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

45 lines
985 B

package main
import (
"net/http"
"time"
"github.com/labstack/echo/v4"
"github.com/sirupsen/logrus"
)
// Logger returns a middleware that logs HTTP requests.
func Logger() echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
req := c.Request()
res := c.Response()
start := time.Now()
var err error
if err = next(c); err != nil {
c.Error(err)
}
stop := time.Now()
reqSize := req.Header.Get(echo.HeaderContentLength)
if reqSize == "" {
reqSize = "0"
}
log.WithFields(logrus.Fields{
"ip": c.RealIP(),
"host": req.Host,
"method": req.Method,
"uri": req.RequestURI,
"status": res.Status,
"request_size": reqSize,
"size": res.Size,
"duration": stop.Sub(start),
"referer": req.Referer(),
"ua": req.UserAgent(),
}).Info(http.StatusText(res.Status))
return err
}
}
}