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

Recovery middleware does not obey gin.DisableConsoleColor() #2505

Open
mgabeler-lee-6rs opened this issue Sep 21, 2020 · 1 comment
Open

Comments

@mgabeler-lee-6rs
Copy link

Description

Recovery middleware does not obey gin.DisableConsoleColor(), but instead has hard coded ansi color sequences always included in its output

How to reproduce

package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
)

func main() {
	gin.DisableConsoleColor()
	g := gin.Default()
	g.GET("/panic", func(c *gin.Context) {
		panic(fmt.Errorf("demo"))
	})
	g.Run(":9000")
}

Expectations

$ curl http://localhost:9000/panic

Expect logged panic output to not have color codes.

Actual result

Logged panic has color codes.

Environment

  • go version: 1.14.x
  • gin version (or commit ref): 1.6.3
  • operating system: Linux

Additional Information

https://github.com/gin-gonic/gin/blob/master/recovery.go#L54 -- this should be using gin.IsOutputColor to determine whether to include color codes in the logger prefix

This is more important when sending the recovery log output through something like zerolog, where the color codes just end up being escape codes inside some other string and have no hope of being rendered.

tkgalk pushed a commit to tkgalk/gin that referenced this issue Oct 1, 2020
@tkgalk
Copy link

tkgalk commented Oct 1, 2020

I have a naive solution to this which works fine but unexports the ConsoleColorMode variable. A more proper solution would be to provide a Logger inside the Recovery as only Logger has Color/Non-Color support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants