8 // logEntry is the JSON payload that gets sent to Stderr from the plugin to the host
10 Message string `json:"@message"`
11 Level string `json:"@level"`
12 Timestamp time.Time `json:"timestamp"`
13 KVPairs []*logEntryKV `json:"kv_pairs"`
16 // logEntryKV is a key value pair within the Output payload
17 type logEntryKV struct {
18 Key string `json:"key"`
19 Value interface{} `json:"value"`
22 // flattenKVPairs is used to flatten KVPair slice into []interface{}
23 // for hclog consumption.
24 func flattenKVPairs(kvs []*logEntryKV) []interface{} {
25 var result []interface{}
26 for _, kv := range kvs {
27 result = append(result, kv.Key)
28 result = append(result, kv.Value)
34 // parseJSON handles parsing JSON output
35 func parseJSON(input string) (*logEntry, error) {
36 var raw map[string]interface{}
39 err := json.Unmarshal([]byte(input), &raw)
44 // Parse hclog-specific objects
45 if v, ok := raw["@message"]; ok {
46 entry.Message = v.(string)
47 delete(raw, "@message")
50 if v, ok := raw["@level"]; ok {
51 entry.Level = v.(string)
55 if v, ok := raw["@timestamp"]; ok {
56 t, err := time.Parse("2006-01-02T15:04:05.000000Z07:00", v.(string))
61 delete(raw, "@timestamp")
64 // Parse dynamic KV args from the hclog payload.
65 for k, v := range raw {
66 entry.KVPairs = append(entry.KVPairs, &logEntryKV{