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
✨ support logging color for custom logging formats #1513
Conversation
can you please provide unittests that test the new code in use and make sure what we expect happens |
How to test for colors in output? Or test the newly added function? |
Use a buffer as weitter in the configuration and check the generated output. |
@amalshaji any progress ? |
working on it now |
if validCustomFormat(cfg.Format) && cfg.Output == nil {
cfg.enableColors = true
} If I use |
ok then use my function to capture the output |
@amalshaji can you please create the tests |
I'm using your function to capture the output. The following code is used for testing the output: func Test_Logger_Custom_Format_Color(t *testing.T) {
output := captureOutput(func() {
app := fiber.New()
app.Use(New(Config{
Format: "",
}))
app.Test(httptest.NewRequest("GET", "/test", nil))
})
fmt.Println("captured Output: ", output)
utils.AssertEqual(t, 5, 5)
} When the format is ❯ go test -timeout 30s -run ^Test_Logger_Custom_Format_Color
captured Output: 18:32:03 | 404 | 0s | 0.0.0.0 | GET | /test
PASS
ok github.com/gofiber/fiber/v2/middleware/logger 0.004s When I use a custom template like ❯ go test -timeout 30s -run ^Test_Logger_Custom_Format_Color
404captured Output:
PASS
ok github.com/gofiber/fiber/v2/middleware/logger 0.005s No output is being captured. Note the 404 printed to stdout. So I decided to disable the validCustomTemplate function and use the previous check, i.e., Got the same output as the empty format one. Unfortunately, the output does not capture any color tags. Also, no color tests were done previously, so I can't refer. |
Yes should be, you can open a issue in https://github.com/gofiber/cli |
@amalshaji that means we do not need the pull request ? the normally come the colors yes or ? |
Only when the format is "" (Empty). The issue was to support colors for custom format. I can't figure out how to test for colors. |
@amalshaji thx for the contribution and effort have unfortunately also found no way from the code it looks good |
Support logger coloring for custom logging formats
Add a function to check for a valid custom format. A valid format is one having both
${status}
and${method}
. Fixed #1467