|
|
|
@ -3,10 +3,13 @@ package log |
|
|
|
|
import ( |
|
|
|
|
"context" |
|
|
|
|
"fmt" |
|
|
|
|
"math" |
|
|
|
|
"runtime" |
|
|
|
|
"strconv" |
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
"github.com/bilibili/kratos/pkg/conf/env" |
|
|
|
|
"github.com/bilibili/kratos/pkg/log/internal/core" |
|
|
|
|
"github.com/bilibili/kratos/pkg/net/metadata" |
|
|
|
|
"github.com/bilibili/kratos/pkg/net/trace" |
|
|
|
|
) |
|
|
|
@ -37,6 +40,28 @@ func addExtraField(ctx context.Context, fields map[string]interface{}) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// toMap convert D slice to map[string]interface{} for legacy file and stdout.
|
|
|
|
|
func toMap(args ...D) map[string]interface{} { |
|
|
|
|
d := make(map[string]interface{}, 10+len(args)) |
|
|
|
|
for _, arg := range args { |
|
|
|
|
switch arg.Type { |
|
|
|
|
case core.UintType, core.Uint64Type, core.IntTpye, core.Int64Type: |
|
|
|
|
d[arg.Key] = arg.Int64Val |
|
|
|
|
case core.StringType: |
|
|
|
|
d[arg.Key] = arg.StringVal |
|
|
|
|
case core.Float32Type: |
|
|
|
|
d[arg.Key] = math.Float32frombits(uint32(arg.Int64Val)) |
|
|
|
|
case core.Float64Type: |
|
|
|
|
d[arg.Key] = math.Float64frombits(uint64(arg.Int64Val)) |
|
|
|
|
case core.DurationType: |
|
|
|
|
d[arg.Key] = time.Duration(arg.Int64Val) |
|
|
|
|
default: |
|
|
|
|
d[arg.Key] = arg.Value |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return d |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// funcName get func name.
|
|
|
|
|
func funcName(skip int) (name string) { |
|
|
|
|
if _, file, lineNo, ok := runtime.Caller(skip); ok { |
|
|
|
|