chore(log): let log toString same (#2414)

pull/2428/head
180909 2 years ago committed by GitHub
parent ff59a89b06
commit 9301bfa407
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      contrib/log/aliyun/aliyun.go
  2. 1
      contrib/log/aliyun/aliyun_test.go
  3. 8
      contrib/log/tencent/tencent.go

@ -2,6 +2,7 @@ package aliyun
import (
"encoding/json"
"fmt"
"strconv"
"time"
@ -164,6 +165,8 @@ func toString(v interface{}) string {
key = strconv.FormatBool(v)
case []byte:
key = string(v)
case fmt.Stringer:
key = v.String()
default:
newValue, _ := json.Marshal(v)
key = string(newValue)

@ -121,6 +121,7 @@ func TestToString(t *testing.T) {
{math.MaxInt64, "9223372036854775807"},
{uint64(math.MaxUint64), "18446744073709551615"},
{"abc", "abc"},
{false, "false"},
{[]byte("abc"), "abc"},
}
for _, test := range tests {

@ -115,7 +115,7 @@ func NewLogger(options ...Option) (Logger, error) {
}, nil
}
// toString any type to string
// toString convert any type to string
func toString(v interface{}) string {
var key string
if v == nil {
@ -146,6 +146,12 @@ func toString(v interface{}) string {
key = strconv.FormatInt(v, 10)
case uint64:
key = strconv.FormatUint(v, 10)
case string:
key = v
case bool:
key = strconv.FormatBool(v)
case []byte:
key = string(v)
case fmt.Stringer:
key = v.String()
default:

Loading…
Cancel
Save