Skip to content
Myr

Truncate Latency precision in long running request (#1830)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

fixes #1823

authored by Dan Markham · committed by 田欧 · parent 1d462bb · Browse files · 2 files+28 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+28 added−0 removed

  • other:+28 added−0 removed

2 files+28 added−0 removed

modified:logger_test.go+24 added
251 unmodified lines
252 Path: "/",253 ErrorMessage: "",254 isTerm: true,255 }256 termTrueLongDurationParam := LogFormatterParams{257 TimeStamp: timeStamp,258 StatusCode: 200,259 Latency: time.Millisecond * 9876543210,260 ClientIP: "20.20.20.20",261 Method: "GET",262 Path: "/",263 ErrorMessage: "",264 isTerm: true,265 }266267 termFalseLongDurationParam := LogFormatterParams{268 TimeStamp: timeStamp,269 StatusCode: 200,270 Latency: time.Millisecond * 9876543210,271 ClientIP: "20.20.20.20",272 Method: "GET",273 Path: "/",274 ErrorMessage: "",275 isTerm: false,276 }277278 assert.Equal(t, "[GIN] 2018/12/07 - 09:11:42 | 200 | 5s | 20.20.20.20 | GET /\n", defaultLogFormatter(termFalseParam))279 assert.Equal(t, "[GIN] 2018/12/07 - 09:11:42 | 200 | 2743h29m3s | 20.20.20.20 | GET /\n", defaultLogFormatter(termFalseLongDurationParam))280281 assert.Equal(t, "[GIN] 2018/12/07 - 09:11:42 |\x1b[97;42m 200 \x1b[0m| 5s | 20.20.20.20 |\x1b[97;44m GET \x1b[0m /\n", defaultLogFormatter(termTrueParam))282 assert.Equal(t, "[GIN] 2018/12/07 - 09:11:42 |\x1b[97;42m 200 \x1b[0m| 2743h29m3s | 20.20.20.20 |\x1b[97;44m GET \x1b[0m /\n", defaultLogFormatter(termTrueLongDurationParam))283284}285286func TestColorForMethod(t *testing.T) {287 colorForMethod := func(method string) string {
147 unmodified lines
modified:logger.go+4 added
134 unmodified lines
135 methodColor = param.MethodColor()136 resetColor = param.ResetColor()137 }138139 if param.Latency > time.Minute {140 // Truncate in a golang < 1.8 safe way141 param.Latency = param.Latency - param.Latency%time.Second142 }143 return fmt.Sprintf("[GIN] %v |%s %3d %s| %13v | %15s |%s %-7s %s %s\n%s",144 param.TimeStamp.Format("2006/01/02 - 15:04:05"),145 statusColor, param.StatusCode, resetColor,146 param.Latency,
124 unmodified lines