[feature] Make client IP logging configurable (#1799)

This commit is contained in:
Daenney
2023-05-21 17:12:47 +02:00
committed by GitHub
parent 68e54cbaa4
commit 107237c8e8
9 changed files with 40 additions and 12 deletions

View File

@@ -31,7 +31,7 @@ import (
)
// Logger returns a gin middleware which provides request logging and panic recovery.
func Logger() gin.HandlerFunc {
func Logger(logClientIP bool) gin.HandlerFunc {
return func(c *gin.Context) {
// Initialize the logging fields
fields := make(kv.Fields, 5, 7)
@@ -72,10 +72,7 @@ func Logger() gin.HandlerFunc {
fields[2] = kv.Field{"method", c.Request.Method}
fields[3] = kv.Field{"statusCode", code}
fields[4] = kv.Field{"path", path}
if includeClientIP := true; includeClientIP {
// TODO: make this configurable.
//
// Include clientIP if enabled.
if logClientIP {
fields = append(fields, kv.Field{
"clientIP", c.ClientIP(),
})