Skip to content

Commit

Permalink
fix: formatter init has no default value
Browse files Browse the repository at this point in the history
  • Loading branch information
樊国睿 committed Sep 28, 2020
1 parent e113ffa commit 12d6e67
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,16 @@ type LoggerConfig struct {

func Logger() gin.HandlerFunc {
return LoggerWithConfig(LoggerConfig{
Logger: logrus.New(),
Formatter: defaultTransformer,
Option: OptionalFieldsParams{},
Logger: logrus.New(),
Option: OptionalFieldsParams{},
})
}
func LoggerWithConfig(config LoggerConfig) gin.HandlerFunc {
logger := config.Logger
formatter := config.Formatter
transformer := config.Formatter
if transformer == nil {
transformer = defaultTransformer
}
var skip map[string]struct{}
if length := len(config.SkipPaths); length > 0 {
skip = make(map[string]struct{}, length)
Expand Down Expand Up @@ -133,7 +135,7 @@ func LoggerWithConfig(config LoggerConfig) gin.HandlerFunc {
path = path + "?" + raw
}
param.Path = path
formatter(logger, param)
transformer(logger, param)
}
}
}

0 comments on commit 12d6e67

Please sign in to comment.