diff --git a/apiary.toml b/apiary.toml index b51c501..a565fba 100644 --- a/apiary.toml +++ b/apiary.toml @@ -38,6 +38,9 @@ LogLevel = "INFO" # Enable access logging # Default: true AccessLogEnable = true +# Disable logging of successful requests to metrics endpoint +# Default: false +AccessLogIgnoreMetrics = false # Address and port to listen to # Default: ":8080" ListenAddr = ":8080" diff --git a/config/config.go b/config/config.go index 3bfa240..c008c77 100644 --- a/config/config.go +++ b/config/config.go @@ -34,10 +34,11 @@ type HoneypotConfig struct { } type FrontendConfig struct { - ListenAddr string `toml:"ListenAddr"` - LogLevel string `toml:"LogLevel"` - AccessLogEnable bool `toml:"AccessLogEnable"` - Autocert FrontendAutocertConfig `toml:"Autocert"` + ListenAddr string `toml:"ListenAddr"` + LogLevel string `toml:"LogLevel"` + AccessLogEnable bool `toml:"AccessLogEnable"` + AccessLogIgnoreMetrics bool `toml:"AccessLogIgnoreMetrics"` + Autocert FrontendAutocertConfig `toml:"Autocert"` } type FrontendAutocertConfig struct { @@ -78,7 +79,7 @@ func FromReader(r io.Reader) (Config, error) { return c, fmt.Errorf("unable to parse config: %w", err) } - //c.readEnv() + // c.readEnv() return c, nil } diff --git a/version.go b/version.go index 7f9dc18..3fc19be 100644 --- a/version.go +++ b/version.go @@ -6,7 +6,7 @@ import ( ) var ( - Version = "v0.1.29" + Version = "v0.1.30" Build string ) diff --git a/web/middleware.go b/web/middleware.go index 6277e9f..c990eb8 100644 --- a/web/middleware.go +++ b/web/middleware.go @@ -17,12 +17,10 @@ func (s *Server) LoggingMiddleware(next http.Handler) http.Handler { reqID := middleware.GetReqID(r.Context()) defer func() { - /*s.AccessLogger.Debugw(r.Method, - "path", r.URL.Path, - "request-headers", r.Header, - "response-headers", ww.Header(), - ) - */ + // If AccessLogIgnoreMetrics is true, do not log successful requests to metrics endpoint + if s.cfg.AccessLogIgnoreMetrics && r.URL.Path == "/metrics" && ww.Status() == http.StatusOK { + return + } s.AccessLogger.Infow(r.Method, "path", r.URL.Path, "status", ww.Status(),