From 6f7a4b69e4d2f73ddb66accd77b3218f3443603b Mon Sep 17 00:00:00 2001 From: zetaozhuang Date: Tue, 16 Aug 2022 15:05:39 -0700 Subject: [PATCH 1/3] feat: extend fieldStringer to support zap ErrorType and BoolType --- zapai/encoder.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/zapai/encoder.go b/zapai/encoder.go index c691bd7b5d..3d3c8c55bc 100644 --- a/zapai/encoder.go +++ b/zapai/encoder.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/gob" "fmt" + "strconv" "sync" "github.com/microsoft/ApplicationInsights-Go/appinsights" @@ -86,8 +87,17 @@ func (g *gobber) decode(b []byte) (*appinsights.TraceTelemetry, error) { // fieldStringer evaluates a zapcore.Field in to a best-effort string. func fieldStringer(f *zapcore.Field) string { - if f.Type == zapcore.StringType { + switch f.Type { + case zapcore.StringType: return f.String + + case zapcore.ErrorType: + return f.Interface.(error).Error() + + case zapcore.BoolType: + return strconv.FormatBool(f.Integer == 1) + + default: + return fmt.Sprintf("%v", f) } - return fmt.Sprintf("%v", f) } From 875a59d9f5a96704b8a2871b2e2f4798403ab786 Mon Sep 17 00:00:00 2001 From: zetaozhuang Date: Thu, 18 Aug 2022 13:44:59 -0700 Subject: [PATCH 2/3] feat: extend fieldStringer to support Int64Type and Uint16Type --- zapai/encoder.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/zapai/encoder.go b/zapai/encoder.go index 3d3c8c55bc..21c45b783e 100644 --- a/zapai/encoder.go +++ b/zapai/encoder.go @@ -91,6 +91,12 @@ func fieldStringer(f *zapcore.Field) string { case zapcore.StringType: return f.String + case zapcore.Int64Type: + return strconv.FormatInt(f.Integer, 10) + + case zapcore.Uint16Type: + return strconv.FormatInt(f.Integer, 10) + case zapcore.ErrorType: return f.Interface.(error).Error() From 917c50305f15d64b90747262627d5898f24fb0d3 Mon Sep 17 00:00:00 2001 From: zetaozhuang Date: Thu, 18 Aug 2022 16:52:14 -0700 Subject: [PATCH 3/3] remove extra empty line --- zapai/encoder.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/zapai/encoder.go b/zapai/encoder.go index 21c45b783e..89024b321d 100644 --- a/zapai/encoder.go +++ b/zapai/encoder.go @@ -90,19 +90,14 @@ func fieldStringer(f *zapcore.Field) string { switch f.Type { case zapcore.StringType: return f.String - case zapcore.Int64Type: return strconv.FormatInt(f.Integer, 10) - case zapcore.Uint16Type: return strconv.FormatInt(f.Integer, 10) - case zapcore.ErrorType: return f.Interface.(error).Error() - case zapcore.BoolType: return strconv.FormatBool(f.Integer == 1) - default: return fmt.Sprintf("%v", f) }