mirror of https://github.com/gin-gonic/gin.git
Use magenta color for HTTP 101 status in the log
When using http.Hijacker, there was a scary looking red log entry. Color it in a more "neutral" color instead, since it is harmless.
This commit is contained in:
parent
02e754be9c
commit
7355f35d1a
|
@ -83,6 +83,8 @@ func (p *LogFormatterParams) StatusCodeColor() string {
|
||||||
code := p.StatusCode
|
code := p.StatusCode
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
|
case code >= http.StatusContinue && code < http.StatusOK:
|
||||||
|
return magenta
|
||||||
case code >= http.StatusOK && code < http.StatusMultipleChoices:
|
case code >= http.StatusOK && code < http.StatusMultipleChoices:
|
||||||
return green
|
return green
|
||||||
case code >= http.StatusMultipleChoices && code < http.StatusBadRequest:
|
case code >= http.StatusMultipleChoices && code < http.StatusBadRequest:
|
||||||
|
|
|
@ -310,6 +310,7 @@ func TestColorForStatus(t *testing.T) {
|
||||||
return p.StatusCodeColor()
|
return p.StatusCodeColor()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert.Equal(t, magenta, colorForStatus(http.StatusSwitchingProtocols), "1xx should be magenta")
|
||||||
assert.Equal(t, green, colorForStatus(http.StatusOK), "2xx should be green")
|
assert.Equal(t, green, colorForStatus(http.StatusOK), "2xx should be green")
|
||||||
assert.Equal(t, white, colorForStatus(http.StatusMovedPermanently), "3xx should be white")
|
assert.Equal(t, white, colorForStatus(http.StatusMovedPermanently), "3xx should be white")
|
||||||
assert.Equal(t, yellow, colorForStatus(http.StatusNotFound), "4xx should be yellow")
|
assert.Equal(t, yellow, colorForStatus(http.StatusNotFound), "4xx should be yellow")
|
||||||
|
|
Loading…
Reference in New Issue