1 Star 0 Fork 0

蓝风网格/log

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
util.go 1.64 KB
一键复制 编辑 原始数据 按行查看 历史
ha666 提交于 2021-06-11 16:14 . 初始化项目
package log
import (
"context"
"math"
"runtime"
"strconv"
"time"
"github.com/ha666/log/internal/core"
)
func addExtraField(ctx context.Context, fields map[string]interface{}) {
//if t, ok := trace.FromContext(ctx); ok {
// fields[_tid] = t.TraceID()
//}
//if caller := metadata.String(ctx, metadata.Caller); caller != "" {
// fields[_caller] = caller
//}
//if color := metadata.String(ctx, metadata.Color); color != "" {
// fields[_color] = color
//}
//if env.Color != "" {
// fields[_envColor] = env.Color
//}
//if cluster := metadata.String(ctx, metadata.Cluster); cluster != "" {
// fields[_cluster] = cluster
//}
//fields[_deplyEnv] = env.DeployEnv
//fields[_zone] = env.Zone
fields[_instanceID] = c.Host
//if metadata.String(ctx, metadata.Mirror) != "" {
// fields[_mirror] = true
//}
}
// funcName get func name.
func funcName(skip int) (name string) {
if _, file, lineNo, ok := runtime.Caller(skip); ok {
return file + ":" + strconv.Itoa(lineNo)
}
return "unknown:0"
}
// 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
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/Balze/log.git
git@gitee.com:Balze/log.git
Balze
log
log
main

搜索帮助