micro/logger/field.go
Shu xian fdfb2bc4c1
[WIP] logger first (#1161)
* logger first

* log->logger

* update comment

* add context in Options

* add Fields

* remove logfi

* add field encode

* add common Field Types

* update logger field
2020-02-06 21:35:46 +00:00

44 lines
617 B
Go

package logger
type FieldType uint8
type Encode func(*Field) string
type Field struct {
Key string
Type FieldType
Value interface{}
Encode Encode
}
func (f *Field) GetValue() interface{} {
if f.Encode != nil {
return f.Encode(f)
}
return f.Value
}
// preset common types for choosing encoder faster
const (
UnknownType FieldType = iota
BoolType
DurationType
Float64Type
Float32Type
Int64Type
Int32Type
Int16Type
Int8Type
Uint64Type
Uint32Type
Uint16Type
Uint8Type
StringType
TimeType
)
func Bool(key string, val bool) Field {
return Field{Key: key, Type: BoolType, Value: val}
}