github.com/vanstinator/golangci-lint@v0.0.0-20240223191551-cc572f00d9d1/pkg/report/log.go (about) 1 package report 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/vanstinator/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 ...any) { 24 lw.origLog.Fatalf(format, args...) 25 } 26 27 func (lw LogWrapper) Panicf(format string, args ...any) { 28 lw.origLog.Panicf(format, args...) 29 } 30 31 func (lw LogWrapper) Errorf(format string, args ...any) { 32 lw.origLog.Errorf(format, args...) 33 lw.rd.Error = fmt.Sprintf(format, args...) 34 } 35 36 func (lw LogWrapper) Warnf(format string, args ...any) { 37 lw.origLog.Warnf(format, args...) 38 w := Warning{ 39 Tag: strings.Join(lw.tags, "/"), 40 Text: fmt.Sprintf(format, args...), 41 } 42 43 lw.rd.Warnings = append(lw.rd.Warnings, w) 44 } 45 46 func (lw LogWrapper) Infof(format string, args ...any) { 47 lw.origLog.Infof(format, args...) 48 } 49 50 func (lw LogWrapper) Child(name string) logutils.Log { 51 c := lw 52 c.origLog = lw.origLog.Child(name) 53 c.tags = append([]string{}, lw.tags...) 54 c.tags = append(c.tags, name) 55 return c 56 } 57 58 func (lw LogWrapper) SetLevel(level logutils.LogLevel) { 59 lw.origLog.SetLevel(level) 60 } 61 62 func (lw LogWrapper) GoString() string { 63 return fmt.Sprintf("lw: %+v, orig log: %#v", lw, lw.origLog) 64 }