github.com/observiq/carbon@v0.9.11-0.20200820160507-1b872e368a5e/errors/details.go (about) 1 package errors 2 3 import "go.uber.org/zap/zapcore" 4 5 // ErrorDetails is a map of details for an agent error. 6 type ErrorDetails map[string]string 7 8 // MarshalLogObject will define the representation of details when logging. 9 func (d ErrorDetails) MarshalLogObject(encoder zapcore.ObjectEncoder) error { 10 for key, value := range d { 11 encoder.AddString(key, value) 12 } 13 return nil 14 } 15 16 // createDetails will create details for an error from key/value pairs. 17 func createDetails(keyValues []string) ErrorDetails { 18 details := make(ErrorDetails) 19 if len(keyValues) > 0 { 20 for i := 0; i+1 < len(keyValues); i += 2 { 21 details[keyValues[i]] = keyValues[i+1] 22 } 23 } 24 return details 25 }