github.com/shulhan/golangci-lint@v1.10.1/pkg/report/log.go (about) 1 package report 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/golangci/golangci-lint/pkg/logutils" 8 ) 9 10 type LogWrapper struct { 11 rd *Data 12 tags []string 13 origLog logutils.Log 14 } 15 16 func NewLogWrapper(log logutils.Log, reportData *Data) *LogWrapper { 17 return &LogWrapper{ 18 rd: reportData, 19 origLog: log, 20 } 21 } 22 23 func (lw LogWrapper) Fatalf(format string, args ...interface{}) { 24 lw.origLog.Fatalf(format, args...) 25 } 26 27 func (lw LogWrapper) Errorf(format string, args ...interface{}) { 28 lw.origLog.Errorf(format, args...) 29 lw.rd.Error = fmt.Sprintf(format, args...) 30 } 31 32 func (lw LogWrapper) Warnf(format string, args ...interface{}) { 33 lw.origLog.Warnf(format, args...) 34 w := Warning{ 35 Tag: strings.Join(lw.tags, "/"), 36 Text: fmt.Sprintf(format, args...), 37 } 38 39 lw.rd.Warnings = append(lw.rd.Warnings, w) 40 } 41 42 func (lw LogWrapper) Infof(format string, args ...interface{}) { 43 lw.origLog.Infof(format, args...) 44 } 45 46 func (lw LogWrapper) Child(name string) logutils.Log { 47 c := lw 48 c.origLog = lw.origLog.Child(name) 49 c.tags = append([]string{}, lw.tags...) 50 c.tags = append(c.tags, name) 51 return c 52 } 53 54 func (lw LogWrapper) SetLevel(level logutils.LogLevel) { 55 lw.origLog.SetLevel(level) 56 } 57 58 func (lw LogWrapper) GoString() string { 59 return fmt.Sprintf("lw: %+v, orig log: %#v", lw, lw.origLog) 60 }