2017-07-26 03:51:49 +00:00
|
|
|
package zerolog
|
|
|
|
|
|
|
|
import (
|
2018-04-03 21:07:18 +00:00
|
|
|
"net"
|
2017-07-26 03:51:49 +00:00
|
|
|
"sort"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func appendFields(dst []byte, fields map[string]interface{}) []byte {
|
|
|
|
keys := make([]string, 0, len(fields))
|
|
|
|
for key := range fields {
|
|
|
|
keys = append(keys, key)
|
|
|
|
}
|
|
|
|
sort.Strings(keys)
|
|
|
|
for _, key := range keys {
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendKey(dst, key)
|
2017-07-26 03:51:49 +00:00
|
|
|
switch val := fields[key].(type) {
|
|
|
|
case string:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendString(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
case []byte:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendBytes(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
case error:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendError(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
case []error:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendErrors(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
case bool:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendBool(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
case int:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendInt(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
case int8:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendInt8(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
case int16:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendInt16(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
case int32:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendInt32(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
case int64:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendInt64(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
case uint:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendUint(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
case uint8:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendUint8(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
case uint16:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendUint16(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
case uint32:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendUint32(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
case uint64:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendUint64(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
case float32:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendFloat32(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
case float64:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendFloat64(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
case time.Time:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendTime(dst, val, TimeFieldFormat)
|
2017-07-26 03:51:49 +00:00
|
|
|
case time.Duration:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendDuration(dst, val, DurationFieldUnit, DurationFieldInteger)
|
2018-03-26 03:18:47 +00:00
|
|
|
case *string:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendString(dst, *val)
|
2018-03-26 03:18:47 +00:00
|
|
|
case *bool:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendBool(dst, *val)
|
2018-03-26 03:18:47 +00:00
|
|
|
case *int:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendInt(dst, *val)
|
2018-03-26 03:18:47 +00:00
|
|
|
case *int8:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendInt8(dst, *val)
|
2018-03-26 03:18:47 +00:00
|
|
|
case *int16:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendInt16(dst, *val)
|
2018-03-26 03:18:47 +00:00
|
|
|
case *int32:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendInt32(dst, *val)
|
2018-03-26 03:18:47 +00:00
|
|
|
case *int64:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendInt64(dst, *val)
|
2018-03-26 03:18:47 +00:00
|
|
|
case *uint:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendUint(dst, *val)
|
2018-03-26 03:18:47 +00:00
|
|
|
case *uint8:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendUint8(dst, *val)
|
2018-03-26 03:18:47 +00:00
|
|
|
case *uint16:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendUint16(dst, *val)
|
2018-03-26 03:18:47 +00:00
|
|
|
case *uint32:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendUint32(dst, *val)
|
2018-03-26 03:18:47 +00:00
|
|
|
case *uint64:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendUint64(dst, *val)
|
2018-03-26 03:18:47 +00:00
|
|
|
case *float32:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendFloat32(dst, *val)
|
2018-03-26 03:18:47 +00:00
|
|
|
case *float64:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendFloat64(dst, *val)
|
2018-03-26 03:18:47 +00:00
|
|
|
case *time.Time:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendTime(dst, *val, TimeFieldFormat)
|
2018-03-26 03:18:47 +00:00
|
|
|
case *time.Duration:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendDuration(dst, *val, DurationFieldUnit, DurationFieldInteger)
|
2017-07-26 03:51:49 +00:00
|
|
|
case []string:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendStrings(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
case []bool:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendBools(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
case []int:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendInts(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
case []int8:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendInts8(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
case []int16:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendInts16(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
case []int32:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendInts32(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
case []int64:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendInts64(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
case []uint:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendUints(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
// case []uint8:
|
|
|
|
// dst = appendUints8(dst, val)
|
|
|
|
case []uint16:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendUints16(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
case []uint32:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendUints32(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
case []uint64:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendUints64(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
case []float32:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendFloats32(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
case []float64:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendFloats64(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
case []time.Time:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendTimes(dst, val, TimeFieldFormat)
|
2017-07-26 03:51:49 +00:00
|
|
|
case []time.Duration:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendDurations(dst, val, DurationFieldUnit, DurationFieldInteger)
|
2017-07-26 03:51:49 +00:00
|
|
|
case nil:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendNil(dst)
|
2018-04-03 21:07:18 +00:00
|
|
|
case net.IP:
|
|
|
|
dst = appendIPAddr(dst, val)
|
|
|
|
case net.IPNet:
|
|
|
|
dst = appendIPPrefix(dst, val)
|
|
|
|
case net.HardwareAddr:
|
|
|
|
dst = appendMACAddr(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
default:
|
2018-03-28 18:49:41 +00:00
|
|
|
dst = appendInterface(dst, val)
|
2017-07-26 03:51:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return dst
|
|
|
|
}
|