blob: a15c2968f30d30fb5e122bb9c77513204d6a0ddf (
plain) (
blame)
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
|
package submitqueue
import (
"time"
"github.com/sirupsen/logrus"
)
// Problem: no inspection during the run
// Problem: record the state
// Result contains all data necessary to inspect a previous run
// This includes the Series from that run, and all Log Entries collected.
// It also implements the interface required for logrus.Hook.
type Result struct {
LogEntries []*logrus.Entry
Series []Serie
Error error
startTime time.Time
HEAD string
}
// MakeResult produces a new Result struct,
// and initializes startTime with the current time.
func MakeResult() *Result {
return &Result{
startTime: time.Now(),
}
}
// StartTime returns the startTime
func (r Result) StartTime() time.Time {
return r.startTime
}
// EndTime returns the time of the latest log entry
func (r Result) EndTime() time.Time {
if len(r.LogEntries) == 0 {
return r.startTime
}
return r.LogEntries[len(r.LogEntries)-1].Time
}
// Fire is called by logrus on each log event,
// we collect all log entries in the struct variable
func (r *Result) Fire(entry *logrus.Entry) error {
r.LogEntries = append(r.LogEntries, entry)
return nil
}
// Levels is called by logrus to determine whether to Fire the handler.
// As we want to collect all log entries, we return logrus.AllLevels
func (r *Result) Levels() []logrus.Level {
return logrus.AllLevels
}
|