-
Notifications
You must be signed in to change notification settings - Fork 1
/
build_logger.go
78 lines (64 loc) · 1.47 KB
/
build_logger.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 common
import (
"fmt"
"github.com/Sirupsen/logrus"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/helpers"
)
type BuildLogger struct {
log BuildTrace
entry *logrus.Entry
}
func (e *BuildLogger) sendLog(logger func(args ...interface{}), logPrefix string, args ...interface{}) {
if e.log != nil {
fmt.Fprint(e.log, logPrefix+fmt.Sprintln(args...)+helpers.ANSI_RESET)
if e.log.IsStdout() {
return
}
}
if len(args) == 0 {
return
}
logger(args...)
}
func (e *BuildLogger) Debugln(args ...interface{}) {
if e.entry == nil {
return
}
e.entry.Debugln(args...)
}
func (e *BuildLogger) Println(args ...interface{}) {
if e.entry == nil {
return
}
e.sendLog(e.entry.Debugln, helpers.ANSI_CLEAR, args...)
}
func (e *BuildLogger) Infoln(args ...interface{}) {
if e.entry == nil {
return
}
e.sendLog(e.entry.Println, helpers.ANSI_BOLD_GREEN, args...)
}
func (e *BuildLogger) Warningln(args ...interface{}) {
if e.entry == nil {
return
}
e.sendLog(e.entry.Warningln, helpers.ANSI_YELLOW+"WARNING: ", args...)
}
func (e *BuildLogger) SoftErrorln(args ...interface{}) {
if e.entry == nil {
return
}
e.sendLog(e.entry.Warningln, helpers.ANSI_BOLD_RED+"ERROR: ", args...)
}
func (e *BuildLogger) Errorln(args ...interface{}) {
if e.entry == nil {
return
}
e.sendLog(e.entry.Errorln, helpers.ANSI_BOLD_RED+"ERROR: ", args...)
}
func NewBuildLogger(log BuildTrace, entry *logrus.Entry) BuildLogger {
return BuildLogger{
log: log,
entry: entry,
}
}