Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [Bug]: Logger Middleware: Enabling color changes padding for some fields #2604

Closed
JShorthouse opened this issue Aug 26, 2023 · 4 comments · Fixed by #2616
Closed

🐛 [Bug]: Logger Middleware: Enabling color changes padding for some fields #2604

JShorthouse opened this issue Aug 26, 2023 · 4 comments · Fixed by #2616

Comments

@JShorthouse
Copy link

JShorthouse commented Aug 26, 2023

The colourization code for {method} and {status} formats the value and adds extra padding either side. This padding is not added when colorization is disabled.

TagStatus: func(output Buffer, c *fiber.Ctx, data *Data, extraParam string) (int, error) {
if cfg.enableColors {
colors := c.App().Config().ColorScheme
return output.WriteString(fmt.Sprintf("%s %3d %s", statusColor(c.Response().StatusCode(), colors), c.Response().StatusCode(), colors.Reset))
}
return appendInt(output, c.Response().StatusCode())
},
TagMethod: func(output Buffer, c *fiber.Ctx, data *Data, extraParam string) (int, error) {
if cfg.enableColors {
colors := c.App().Config().ColorScheme
return output.WriteString(fmt.Sprintf("%s %-7s %s", methodColor(c.Method(), colors), c.Method(), colors.Reset))
}
return output.WriteString(c.Method())
},

This discrepency is immediately obvious when using a custom format that puts these values in brackets, e.g:

"${time} [${locals:requestid}: ${ip}] (${status}) [${method}] ${path}​\n"

With DisableColours: false:

image

DisableColours: true:

image

@welcome
Copy link

welcome bot commented Aug 26, 2023

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

@JShorthouse
Copy link
Author

Personally I can live with the 7 character padding on the method type because it makes sense for "pretty printing" to ensure a constant width for all possible values.

But the single extra spaces on each side really threw me off. There's currently no way for me to remove that space and keep the colours on. I don't think having that spacing makes much sense, if people want an extra space either side they can just add it to their format string like: ( ${status} ) [ ${method} ]

@AKARSHITJOSHI
Copy link
Contributor

AKARSHITJOSHI commented Sep 1, 2023

@JShorthouse are we looking to remove the extra spacing or add extra spaces when DisableColours: false ??

@JShorthouse
Copy link
Author

I think removing the spacing would make more sense

ReneWerner87 pushed a commit that referenced this issue Sep 11, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
…lds #2604  (#2616)

🐛 Removes extra padding for response code, method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants