mirror of
https://github.com/kemko/reproxy.git
synced 2026-01-01 15:55:49 +03:00
filter /ping from stdout logging
This commit is contained in:
@@ -90,7 +90,7 @@ func (h *Http) Run(ctx context.Context) error {
|
||||
h.pingHandler,
|
||||
h.healthMiddleware,
|
||||
h.accessLogHandler(h.AccessLog),
|
||||
h.stdoutLogHandler(h.StdOutEnabled),
|
||||
h.stdoutLogHandler(h.StdOutEnabled, logger.New(logger.Log(log.Default()), logger.Prefix("[INFO]")).Handler),
|
||||
R.SizeLimit(h.MaxBodySize),
|
||||
R.Headers(h.ProxyHeaders...),
|
||||
h.gzipHandler(),
|
||||
@@ -243,10 +243,20 @@ func (h *Http) accessLogHandler(wr io.Writer) func(next http.Handler) http.Handl
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Http) stdoutLogHandler(enable bool) func(next http.Handler) http.Handler {
|
||||
func (h *Http) stdoutLogHandler(enable bool, lh func(next http.Handler) http.Handler) func(next http.Handler) http.Handler {
|
||||
|
||||
if enable {
|
||||
return logger.New(logger.Log(log.Default()), logger.Prefix("[INFO]")).Handler
|
||||
return func(next http.Handler) http.Handler {
|
||||
fn := func(w http.ResponseWriter, r *http.Request) {
|
||||
// don't log to stdout GET ~/(.*)/ping$ requests
|
||||
if r.Method == "GET" && strings.HasSuffix(r.URL.Path, "/ping") {
|
||||
next.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
lh(next).ServeHTTP(w, r)
|
||||
}
|
||||
return http.HandlerFunc(fn)
|
||||
}
|
||||
}
|
||||
|
||||
return func(next http.Handler) http.Handler {
|
||||
|
||||
Reference in New Issue
Block a user