Can we export the defaultLogFormatter
below (DefaultLogFormatter
)?
https://github.com/gin-gonic/gin/blob/bb1fc2e0fe97c63dab1527baab88d01183853b8f/logger.go#L132-L132
In doing so it would be very easy to configure any of the gin.LogFormatterParams
, eg:
return gin.LoggerWithConfig(gin.LoggerConfig{
Formatter: func(param gin.LogFormatterParams) string {
// Remove query params from log
param.Path = strings.Split(param.Path, "?")[0]
return gin.DefaultLogFormatter(param)
}
})
Currently, to achieve the same result from the above code, I had to copy the entire defaultLogFormatter
implementation just to remove the query params from log:
return gin.LoggerWithConfig(gin.LoggerConfig{
Formatter: func(param gin.LogFormatterParams) string {
var statusColor, methodColor, resetColor string
if param.IsOutputColor() {
statusColor = param.StatusCodeColor()
methodColor = param.MethodColor()
resetColor = param.ResetColor()
}
if param.Latency > time.Minute {
param.Latency = param.Latency - param.Latency%time.Second
}
return fmt.Sprintf("[GIN] %v |%s %3d %s| %13v | %15s |%s %-7s %s %#v\n%s",
param.TimeStamp.Format("2006/01/02 - 15:04:05"),
statusColor, param.StatusCode, resetColor,
param.Latency,
param.ClientIP,
methodColor, param.Method, resetColor,
// Remove query params from log
strings.Split(param.Path, "?")[0],
param.ErrorMessage,
)
})