-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Labels
Description
Bug Description
I'm filing this as a bug since I think the behaviour is counter-intuitive.
The logger middleware has a configuration with a default format:
fiber/middleware/logger/config.go
Line 89 in 2374cad
| Format: "[${time}] ${status} - ${latency} ${method} ${path}\n", |
However, when the logger proceeds to print this, it ignores the actual format:
fiber/middleware/logger/logger.go
Lines 141 to 174 in 2374cad
| if cfg.Format == ConfigDefault.Format { | |
| // Format error if exist | |
| formatErr := "" | |
| if cfg.enableColors { | |
| if chainErr != nil { | |
| formatErr = colors.Red + " | " + chainErr.Error() + colors.Reset | |
| } | |
| _, _ = buf.WriteString( //nolint:errcheck // This will never fail | |
| fmt.Sprintf("%s |%s %3d %s| %13v | %15s |%s %-7s %s| %-"+errPaddingStr+"s %s\n", | |
| timestamp.Load().(string), | |
| statusColor(c.Response().StatusCode(), colors), c.Response().StatusCode(), colors.Reset, | |
| data.Stop.Sub(data.Start), | |
| c.IP(), | |
| methodColor(c.Method(), colors), c.Method(), colors.Reset, | |
| c.Path(), | |
| formatErr, | |
| ), | |
| ) | |
| } else { | |
| if chainErr != nil { | |
| formatErr = " | " + chainErr.Error() | |
| } | |
| _, _ = buf.WriteString( //nolint:errcheck // This will never fail | |
| fmt.Sprintf("%s | %3d | %13v | %15s | %-7s | %-"+errPaddingStr+"s %s\n", | |
| timestamp.Load().(string), | |
| c.Response().StatusCode(), | |
| data.Stop.Sub(data.Start), | |
| c.IP(), | |
| c.Method(), | |
| c.Path(), | |
| formatErr, | |
| ), | |
| ) | |
| } |
Despite it checking for if it should use the default format, it then uses a different format string in the fmt.Sprintf() calls.
How to Reproduce
- Add the logging middleware without overriding the
Format - Do a request and observe the log output
Expected Behavior
Logged line should use the ConfigDefault.Format for output, as shown in the configuration: https://docs.gofiber.io/api/middleware/logger#default-config
Fiber Version
v2.50.0
Code Snippet (optional)
No response
Checklist:
- I agree to follow Fiber's Code of Conduct.
- I have checked for existing issues that describe my problem prior to opening this one.
- I understand that improperly formatted bug reports may be closed without explanation.
Reactions are currently unavailable