go(app/server): skip logging /assets visits
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
15994c9d8f
commit
010e54168a
@ -6,11 +6,13 @@ package app
|
|||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"regexp"
|
||||||
|
|
||||||
"github.com/gorilla/sessions"
|
"github.com/gorilla/sessions"
|
||||||
"github.com/labstack/echo-contrib/session"
|
"github.com/labstack/echo-contrib/session"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/labstack/echo/v4/middleware"
|
"github.com/labstack/echo/v4/middleware"
|
||||||
|
"golang.org/x/exp/slog"
|
||||||
"golang.org/x/time/rate"
|
"golang.org/x/time/rate"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -20,7 +22,22 @@ func (a *App) SetServerSettings() {
|
|||||||
|
|
||||||
e.HideBanner = true
|
e.HideBanner = true
|
||||||
|
|
||||||
|
if a.setting.DefaultLoggerSkipAssets() {
|
||||||
|
re := regexp.MustCompile("^/(assets|static)(.*)|favicon.ico")
|
||||||
|
lC := middleware.DefaultLoggerConfig
|
||||||
|
|
||||||
|
lC.Skipper = func(c echo.Context) bool {
|
||||||
|
r := c.Request().URL.Path
|
||||||
|
|
||||||
|
slog.Debug("logger skipper", "path", r)
|
||||||
|
|
||||||
|
return re.MatchString(r)
|
||||||
|
}
|
||||||
|
e.Use(middleware.LoggerWithConfig(lC))
|
||||||
|
} else {
|
||||||
e.Use(middleware.Logger())
|
e.Use(middleware.Logger())
|
||||||
|
}
|
||||||
|
|
||||||
// e.Use(middleware.LoggerWithConfig(
|
// e.Use(middleware.LoggerWithConfig(
|
||||||
// middleware.LoggerConfig{
|
// middleware.LoggerConfig{
|
||||||
// Format: `{"time":"${time_rfc3339_nano}","id":"${id}","remote_ip":"${remote_ip}",` +
|
// Format: `{"time":"${time_rfc3339_nano}","id":"${id}","remote_ip":"${remote_ip}",` +
|
||||||
|
@ -49,6 +49,7 @@ const (
|
|||||||
defaultHTTPDomain = "localhost"
|
defaultHTTPDomain = "localhost"
|
||||||
defaultServerWriteTimeout = 30 * time.Second
|
defaultServerWriteTimeout = 30 * time.Second
|
||||||
defaultServerReadHeaderTimeout = 30 * time.Second
|
defaultServerReadHeaderTimeout = 30 * time.Second
|
||||||
|
defaultLoggerSkipAssets = true
|
||||||
)
|
)
|
||||||
|
|
||||||
// cleantgt is a list of ENV vars pertaining to pcmt.
|
// cleantgt is a list of ENV vars pertaining to pcmt.
|
||||||
@ -78,6 +79,11 @@ func (s *Settings) DefaultServerReadHeaderTimeout() time.Duration {
|
|||||||
return defaultServerReadHeaderTimeout
|
return defaultServerReadHeaderTimeout
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DefaultLoggerSkipAssets returns whether the logger skips reporting asset visits.
|
||||||
|
func (s *Settings) DefaultLoggerSkipAssets() bool {
|
||||||
|
return defaultLoggerSkipAssets
|
||||||
|
}
|
||||||
|
|
||||||
// Consolidate reconciles whatever values are set in config and via flags and
|
// Consolidate reconciles whatever values are set in config and via flags and
|
||||||
// sets it to one place that should be regarded as a single source of truth -
|
// sets it to one place that should be regarded as a single source of truth -
|
||||||
// the settings struct. Order of preference for values is (from higher to
|
// the settings struct. Order of preference for values is (from higher to
|
||||||
|
Loading…
Reference in New Issue
Block a user