代码拉取完成,页面将自动刷新
package log
import (
"fmt"
"strings"
"time"
)
type FiledType int
const (
TypeString FiledType = iota
TypeBool
TypeInt
TypeFloat
TypeAny
)
type Field struct {
Key string
Val FiledValue
}
type FiledValue struct {
V interface{}
T FiledType
}
func String(key, val string) Field {
return Field{
Key: key,
Val: FiledValue{
V: val,
T: TypeString,
},
}
}
func Float64(key string, val float64) Field {
return Field{
Key: key,
Val: FiledValue{
V: val,
T: TypeFloat,
},
}
}
func Bool(key string, val bool) Field {
return Field{
Key: key,
Val: FiledValue{
V: val,
T: TypeBool,
},
}
}
func Int64(key string, val int64) Field {
return Field{
Key: key,
Val: FiledValue{
V: val,
T: TypeInt,
},
}
}
func Int(key string, val int) Field {
return Field{
Key: key,
Val: FiledValue{
V: val,
T: TypeInt,
},
}
}
func Int32(key string, val int32) Field {
return Field{
Key: key,
Val: FiledValue{
V: val,
T: TypeInt,
},
}
}
func UInt(key string, val uint) Field {
return Field{
Key: key,
Val: FiledValue{
V: val,
T: TypeInt,
},
}
}
func Duration(key string, val time.Duration) Field {
return Field{
Key: key,
Val: FiledValue{
V: val,
T: TypeString,
},
}
}
func Any(key string, val interface{}) Field {
return Field{
Key: key,
Val: FiledValue{
V: val,
T: TypeAny,
},
}
}
func FieldString(key, value string) Field {
value = strings.Replace(value, " ", ".", -1)
return String(key, value)
}
func FieldMod(value string) Field {
return FieldString("mod", value)
}
func FieldErr(err error) Field {
if err == nil {
return Field{
Key: "err",
Val: FiledValue{
V: "",
T: TypeString,
},
}
}
return Field{
Key: "err",
Val: FiledValue{
V: err.Error(),
T: TypeString,
},
}
}
func FieldKey(value string) Field {
return String("key", value)
}
func FieldAddr(value string) Field {
return String("addr", value)
}
func FieldName(value string) Field {
return String("name", value)
}
// FieldType ...
func FieldType(value string) Field {
return String("type", value)
}
// FieldMessage ...
func FieldMessage(value string) Field {
return String("message", value)
}
func FieldErrKind(value string) Field {
return String("errKind", value)
}
// FieldMethod ...
func FieldMethod(value string) Field {
return String("method", value)
}
// FieldEvent ...
func FieldEvent(value string) Field {
return String("event", value)
}
// FieldCost 耗时时间
func FieldCost(value time.Duration) Field {
return String("cost", fmt.Sprintf("%.3f(ms)", float64(value.Round(time.Microsecond))/float64(time.Millisecond)))
}
// FieldStack ...
func FieldStack(value []byte) Field {
return String("stack", string(value))
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。