feat: make user-agent optional in the NewWithConfig (#9)
* feat: make user-agent optional in the NewWithConfig * feat: set default value to false
This commit is contained in:
+8
-3
@@ -41,6 +41,7 @@ type Config struct {
|
|||||||
ClientErrorLevel slog.Level
|
ClientErrorLevel slog.Level
|
||||||
ServerErrorLevel slog.Level
|
ServerErrorLevel slog.Level
|
||||||
|
|
||||||
|
WithUserAgent bool
|
||||||
WithRequestID bool
|
WithRequestID bool
|
||||||
WithRequestBody bool
|
WithRequestBody bool
|
||||||
WithRequestHeader bool
|
WithRequestHeader bool
|
||||||
@@ -62,6 +63,7 @@ func New(logger *slog.Logger) gin.HandlerFunc {
|
|||||||
ClientErrorLevel: slog.LevelWarn,
|
ClientErrorLevel: slog.LevelWarn,
|
||||||
ServerErrorLevel: slog.LevelError,
|
ServerErrorLevel: slog.LevelError,
|
||||||
|
|
||||||
|
WithUserAgent: false,
|
||||||
WithRequestID: true,
|
WithRequestID: true,
|
||||||
WithRequestBody: false,
|
WithRequestBody: false,
|
||||||
WithRequestHeader: false,
|
WithRequestHeader: false,
|
||||||
@@ -69,8 +71,7 @@ func New(logger *slog.Logger) gin.HandlerFunc {
|
|||||||
WithResponseHeader: false,
|
WithResponseHeader: false,
|
||||||
WithSpanID: false,
|
WithSpanID: false,
|
||||||
WithTraceID: false,
|
WithTraceID: false,
|
||||||
|
Filters: []Filter{},
|
||||||
Filters: []Filter{},
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,6 +85,7 @@ func NewWithFilters(logger *slog.Logger, filters ...Filter) gin.HandlerFunc {
|
|||||||
ClientErrorLevel: slog.LevelWarn,
|
ClientErrorLevel: slog.LevelWarn,
|
||||||
ServerErrorLevel: slog.LevelError,
|
ServerErrorLevel: slog.LevelError,
|
||||||
|
|
||||||
|
WithUserAgent: false,
|
||||||
WithRequestID: true,
|
WithRequestID: true,
|
||||||
WithRequestBody: false,
|
WithRequestBody: false,
|
||||||
WithRequestHeader: false,
|
WithRequestHeader: false,
|
||||||
@@ -140,10 +142,13 @@ func NewWithConfig(logger *slog.Logger, config Config) gin.HandlerFunc {
|
|||||||
slog.String("route", c.FullPath()),
|
slog.String("route", c.FullPath()),
|
||||||
slog.String("ip", c.ClientIP()),
|
slog.String("ip", c.ClientIP()),
|
||||||
slog.Duration("latency", latency),
|
slog.Duration("latency", latency),
|
||||||
slog.String("user-agent", c.Request.UserAgent()),
|
|
||||||
slog.Time("time", end),
|
slog.Time("time", end),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.WithUserAgent {
|
||||||
|
attributes = append(attributes, slog.String("user-agent", c.Request.UserAgent()))
|
||||||
|
}
|
||||||
|
|
||||||
if config.WithRequestID {
|
if config.WithRequestID {
|
||||||
attributes = append(attributes, slog.String("request-id", requestID))
|
attributes = append(attributes, slog.String("request-id", requestID))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user