From a321e050733fd76d3fe513755cd5bb13836831d2 Mon Sep 17 00:00:00 2001 From: 8treenet <4932004@qq.com> Date: Wed, 5 Jul 2023 17:48:31 +0800 Subject: [PATCH] Access log switch. --- middleware/logger_config.go | 2 ++ middleware/request_logger.go | 3 +++ 2 files changed, 5 insertions(+) diff --git a/middleware/logger_config.go b/middleware/logger_config.go index 6b0e528..0e4bea8 100644 --- a/middleware/logger_config.go +++ b/middleware/logger_config.go @@ -12,6 +12,7 @@ type skipperFunc func(ctx context.Context) bool // RequestLoggerConfig Contains the options for the logger middleware // can be optionally be passed to the `New`. type RequestLoggerConfig struct { + Access bool IP bool Query bool MessageContextKeys []string @@ -77,6 +78,7 @@ type RequestLoggerConfig struct { // LogFunc and Skippers to nil as well. func DefaultLoggerConfig() *RequestLoggerConfig { return &RequestLoggerConfig{ + Access: true, IP: false, Query: true, RequestRawBody: true, diff --git a/middleware/request_logger.go b/middleware/request_logger.go index b4b28d8..d54f7e2 100644 --- a/middleware/request_logger.go +++ b/middleware/request_logger.go @@ -61,6 +61,9 @@ func (l *requestLoggerMiddleware) ServeHTTP(ctx context.Context) { if !work.IsDeferRecycle() { loggerPool.Put(freelog) } + if !l.config.Access { + return + } // no time.Since in order to format it well after endTime = time.Now()