gitlab.com/jfprevost/gitlab-runner-notlscheck@v11.11.4+incompatible/common/build_logger.go (about) 1 package common 2 3 import ( 4 "fmt" 5 6 "github.com/sirupsen/logrus" 7 8 "gitlab.com/gitlab-org/gitlab-runner/helpers" 9 "gitlab.com/gitlab-org/gitlab-runner/helpers/url" 10 ) 11 12 type BuildLogger struct { 13 log JobTrace 14 entry *logrus.Entry 15 } 16 17 func (e *BuildLogger) WithFields(fields logrus.Fields) BuildLogger { 18 return NewBuildLogger(e.log, e.entry.WithFields(fields)) 19 } 20 21 func (e *BuildLogger) SendRawLog(args ...interface{}) { 22 if e.log != nil { 23 fmt.Fprint(e.log, args...) 24 } 25 } 26 27 func (e *BuildLogger) sendLog(logger func(args ...interface{}), logPrefix string, args ...interface{}) { 28 if e.log != nil { 29 logLine := url_helpers.ScrubSecrets(logPrefix + fmt.Sprintln(args...)) 30 e.SendRawLog(logLine) 31 e.SendRawLog(helpers.ANSI_RESET) 32 33 if e.log.IsStdout() { 34 return 35 } 36 } 37 38 if len(args) == 0 { 39 return 40 } 41 42 logger(args...) 43 } 44 45 func (e *BuildLogger) Debugln(args ...interface{}) { 46 if e.entry == nil { 47 return 48 } 49 e.entry.Debugln(args...) 50 } 51 52 func (e *BuildLogger) Println(args ...interface{}) { 53 if e.entry == nil { 54 return 55 } 56 e.sendLog(e.entry.Debugln, helpers.ANSI_CLEAR, args...) 57 } 58 59 func (e *BuildLogger) Infoln(args ...interface{}) { 60 if e.entry == nil { 61 return 62 } 63 e.sendLog(e.entry.Println, helpers.ANSI_BOLD_GREEN, args...) 64 } 65 66 func (e *BuildLogger) Warningln(args ...interface{}) { 67 if e.entry == nil { 68 return 69 } 70 e.sendLog(e.entry.Warningln, helpers.ANSI_YELLOW+"WARNING: ", args...) 71 } 72 73 func (e *BuildLogger) SoftErrorln(args ...interface{}) { 74 if e.entry == nil { 75 return 76 } 77 e.sendLog(e.entry.Warningln, helpers.ANSI_BOLD_RED+"ERROR: ", args...) 78 } 79 80 func (e *BuildLogger) Errorln(args ...interface{}) { 81 if e.entry == nil { 82 return 83 } 84 e.sendLog(e.entry.Errorln, helpers.ANSI_BOLD_RED+"ERROR: ", args...) 85 } 86 87 func NewBuildLogger(log JobTrace, entry *logrus.Entry) BuildLogger { 88 return BuildLogger{ 89 log: log, 90 entry: entry, 91 } 92 }