File size: 1,426 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package harness

import (
	"encoding/json"
	"io"
	"strings"
)

func (h *Harness) watchBackendLogs(r io.Reader) {
	dec := json.NewDecoder(r)
	var entry struct {
		Error        string
		Message      string `json:"msg"`
		Source       string
		Level        string
		SQL          string
		ProviderType string
		URL          string
	}

	ignore := func(msg string) bool {
		h.mx.Lock()
		defer h.mx.Unlock()
		for _, s := range h.ignoreErrors {
			if strings.Contains(msg, s) {
				return true
			}
		}
		return false
	}

	h.IgnoreErrorsWith("rotation advanced late")

	var err error
	for {
		var raw json.RawMessage
		err = dec.Decode(&raw)
		if err != nil {
			break
		}

		err = json.Unmarshal(raw, &entry)
		if err != nil {
			break
		}

		if ignore(entry.Error) {
			entry.Level = "ignore[" + entry.Level + "]"
		}
		if entry.Level == "error" || entry.Level == "fatal" {
			if entry.SQL != "" {
				// ignore printed SQL errors
				continue
			}
			h.t.Errorf("Backend: %s(%s) %s: %s\n%s", strings.ToUpper(entry.Level), entry.Source, entry.Error, entry.Message, string(raw))
			continue
		} else {
			h.t.Logf("Backend: %s %s", strings.ToUpper(entry.Level), entry.Message)
		}
	}
	if h.isClosing() {
		return
	}
	data := make([]byte, 32768)
	n, _ := dec.Buffered().Read(data)
	nx, _ := r.Read(data[n:])
	if n+nx > 0 {
		h.t.Logf("Buffered: %s", string(data[:n+nx]))
	}

	h.t.Errorf("failed to read/parse JSON logs: %v", err)
}