New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
馃 Strange behaviour of the logger when adding tag "method" TagMethod into formatting string #1609
Comments
Thanks for opening your first issue here! 馃帀 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
interesting. I will look into it. |
Previous solution to fixing the custom color issue was okay, but did not take into account how the coloring was done in the background. Here, if colors are enabled, it colors the default format. Because the previous fix did not account for the custom template. Solution is to make changes to this switch tag if validCustomFormat(cfg.Format) && cfg.Output == nil {
cfg.enableColors = 0
}
if cfg.Format == "" && cfg.Output == nil {
cfg.enableColors = 1
} Line 177 becomes, if cfg.enableColors == 1 {
....
} Line 240 becomes, case TagStatus:
if cfg.enableColors == 0 {
resp := fmt.Sprintf("%s %3d %s", statusColor(c.Response().StatusCode()), c.Response().StatusCode(), cReset)
return appendInt(buf, resp)
}
return appendInt(buf, c.Response().StatusCode()) Similar change to Line 246 A lot of changes here. There's also a case of tests. What do you think? |
Probably question is not for me, but I think that flag cfg.enableColors has no place in configuration and the way it is tested (cfg.Format == "" && cfg.Output == nil) does not correspond to it's name. Maybe there is a need for deeper refactoring. |
v 2.21.0
Adding tag "method" TagMethod in custom format, force using of the default formatting and completely ignoring custom one
Magic is in a function
fiber/middleware/logger/config.go
Line 61 in 85591e8
checking for 2 keywords one of them is "method", used in configDefault
fiber/middleware/logger/config.go
Line 85 in 85591e8
A decision is made to enable colors in configuration.
Which is the root of the problem because same flag is used in decision, default formatting to be used. 馃槼
fiber/middleware/logger/logger.go
Line 177 in 85591e8
Code snippet
The text was updated successfully, but these errors were encountered: