Skip to content
This repository was archived by the owner on Nov 5, 2024. It is now read-only.

Commit db77644

Browse files
committed
[proxy]日志格式化时float直接转换为带点的小数
1 parent 72309a6 commit db77644

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

tealogs/accesslogs/access_log.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,14 @@ func (this *AccessLog) Format(format string) string {
183183
if found {
184184
field := refValue.FieldByName(fieldName)
185185
if field.IsValid() {
186-
if field.Kind() == reflect.String {
186+
kind := field.Kind()
187+
switch kind {
188+
case reflect.String:
187189
return field.String()
188-
} else {
189-
return fmt.Sprintf("%#v", field.Interface())
190+
case reflect.Float32, reflect.Float64:
191+
return fmt.Sprintf("%f", field.Interface())
192+
default:
193+
return types.String(field.Interface())
190194
}
191195
}
192196

tealogs/accesslogs/access_log_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,13 @@ func TestAccessLog_Format(t *testing.T) {
280280
t.Log(accessLog.Format(format))
281281
}
282282

283+
func TestAccessLog_FormatFloat(t *testing.T) {
284+
accessLog := &AccessLog{
285+
RequestTime: 7.964e-5,
286+
}
287+
t.Log(accessLog.Format("${requestTime}"))
288+
}
289+
283290
func TestAccessLog_ParseGEO(t *testing.T) {
284291
teageo.SetupDB()
285292

0 commit comments

Comments
 (0)