-
Notifications
You must be signed in to change notification settings - Fork 0
/
logsGatherer.go
78 lines (61 loc) · 1.71 KB
/
logsGatherer.go
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
74
75
76
77
78
package mock
import (
"strings"
"sync"
logger "github.com/Reshusk23/dme-go-logger"
)
// DummyLogsGatherer -
type DummyLogsGatherer struct {
lines []logger.LogLineHandler
text strings.Builder
mutex sync.RWMutex
}
// Write -
func (gatherer *DummyLogsGatherer) Write(p []byte) (n int, err error) {
return 0, nil
}
// Output -
func (gatherer *DummyLogsGatherer) Output(line logger.LogLineHandler) []byte {
gatherer.mutex.Lock()
defer gatherer.mutex.Unlock()
gatherer.lines = append(gatherer.lines, line)
gatherer.gatherText(line)
return make([]byte, 0)
}
func (gatherer *DummyLogsGatherer) gatherText(line logger.LogLineHandler) {
gatherer.text.WriteString(line.GetMessage() + "\n")
for _, arg := range line.GetArgs() {
gatherer.text.WriteString(arg + "\n")
}
}
// GetText -
func (gatherer *DummyLogsGatherer) GetText() string {
gatherer.mutex.RLock()
defer gatherer.mutex.RUnlock()
return gatherer.text.String()
}
// ContainsText -
func (gatherer *DummyLogsGatherer) ContainsText(str string) bool {
gatherer.mutex.RLock()
defer gatherer.mutex.RUnlock()
text := gatherer.text.String()
return strings.Contains(text, str)
}
// ContainsLogLine -
func (gatherer *DummyLogsGatherer) ContainsLogLine(loggerName string, level logger.LogLevel, message string) bool {
gatherer.mutex.RLock()
defer gatherer.mutex.RUnlock()
for _, line := range gatherer.lines {
matchedLevel := line.GetLogLevel() == int32(level)
matchedMessage := line.GetMessage() == message
matchedLogger := line.GetLoggerName() == loggerName
if matchedLevel && matchedMessage && matchedLogger {
return true
}
}
return false
}
// IsInterfaceNil -
func (gatherer *DummyLogsGatherer) IsInterfaceNil() bool {
return gatherer == nil
}