AddTo exports a field through the ObjectEncoder interface. It's primarily useful to library authors, and shouldn't be necessary in most applications.
(enc ObjectEncoder)
| 112 | // AddTo exports a field through the ObjectEncoder interface. It's primarily |
| 113 | // useful to library authors, and shouldn't be necessary in most applications. |
| 114 | func (f Field) AddTo(enc ObjectEncoder) { |
| 115 | var err error |
| 116 | |
| 117 | switch f.Type { |
| 118 | case ArrayMarshalerType: |
| 119 | err = enc.AddArray(f.Key, f.Interface.(ArrayMarshaler)) |
| 120 | case ObjectMarshalerType: |
| 121 | err = enc.AddObject(f.Key, f.Interface.(ObjectMarshaler)) |
| 122 | case InlineMarshalerType: |
| 123 | err = f.Interface.(ObjectMarshaler).MarshalLogObject(enc) |
| 124 | case BinaryType: |
| 125 | enc.AddBinary(f.Key, f.Interface.([]byte)) |
| 126 | case BoolType: |
| 127 | enc.AddBool(f.Key, f.Integer == 1) |
| 128 | case ByteStringType: |
| 129 | enc.AddByteString(f.Key, f.Interface.([]byte)) |
| 130 | case Complex128Type: |
| 131 | enc.AddComplex128(f.Key, f.Interface.(complex128)) |
| 132 | case Complex64Type: |
| 133 | enc.AddComplex64(f.Key, f.Interface.(complex64)) |
| 134 | case DurationType: |
| 135 | enc.AddDuration(f.Key, time.Duration(f.Integer)) |
| 136 | case Float64Type: |
| 137 | enc.AddFloat64(f.Key, math.Float64frombits(uint64(f.Integer))) |
| 138 | case Float32Type: |
| 139 | enc.AddFloat32(f.Key, math.Float32frombits(uint32(f.Integer))) |
| 140 | case Int64Type: |
| 141 | enc.AddInt64(f.Key, f.Integer) |
| 142 | case Int32Type: |
| 143 | enc.AddInt32(f.Key, int32(f.Integer)) |
| 144 | case Int16Type: |
| 145 | enc.AddInt16(f.Key, int16(f.Integer)) |
| 146 | case Int8Type: |
| 147 | enc.AddInt8(f.Key, int8(f.Integer)) |
| 148 | case StringType: |
| 149 | enc.AddString(f.Key, f.String) |
| 150 | case TimeType: |
| 151 | if f.Interface != nil { |
| 152 | enc.AddTime(f.Key, time.Unix(0, f.Integer).In(f.Interface.(*time.Location))) |
| 153 | } else { |
| 154 | // Fall back to UTC if location is nil. |
| 155 | enc.AddTime(f.Key, time.Unix(0, f.Integer)) |
| 156 | } |
| 157 | case TimeFullType: |
| 158 | enc.AddTime(f.Key, f.Interface.(time.Time)) |
| 159 | case Uint64Type: |
| 160 | enc.AddUint64(f.Key, uint64(f.Integer)) |
| 161 | case Uint32Type: |
| 162 | enc.AddUint32(f.Key, uint32(f.Integer)) |
| 163 | case Uint16Type: |
| 164 | enc.AddUint16(f.Key, uint16(f.Integer)) |
| 165 | case Uint8Type: |
| 166 | enc.AddUint8(f.Key, uint8(f.Integer)) |
| 167 | case UintptrType: |
| 168 | enc.AddUintptr(f.Key, uintptr(f.Integer)) |
| 169 | case ReflectType: |
| 170 | err = enc.AddReflected(f.Key, f.Interface) |
| 171 | case NamespaceType: |