forked from golangci/golangci-lint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
64 lines (51 loc) · 1.33 KB
/
log.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
package report
import (
"fmt"
"strings"
"github.com/chenfeining/golangci-lint/pkg/logutils"
)
type LogWrapper struct {
rd *Data
tags []string
origLog logutils.Log
}
func NewLogWrapper(log logutils.Log, reportData *Data) *LogWrapper {
return &LogWrapper{
rd: reportData,
origLog: log,
}
}
func (lw LogWrapper) Fatalf(format string, args ...any) {
lw.origLog.Fatalf(format, args...)
}
func (lw LogWrapper) Panicf(format string, args ...any) {
lw.origLog.Panicf(format, args...)
}
func (lw LogWrapper) Errorf(format string, args ...any) {
lw.origLog.Errorf(format, args...)
lw.rd.Error = fmt.Sprintf(format, args...)
}
func (lw LogWrapper) Warnf(format string, args ...any) {
lw.origLog.Warnf(format, args...)
w := Warning{
Tag: strings.Join(lw.tags, "/"),
Text: fmt.Sprintf(format, args...),
}
lw.rd.Warnings = append(lw.rd.Warnings, w)
}
func (lw LogWrapper) Infof(format string, args ...any) {
lw.origLog.Infof(format, args...)
}
func (lw LogWrapper) Child(name string) logutils.Log {
c := lw
c.origLog = lw.origLog.Child(name)
c.tags = append([]string{}, lw.tags...)
c.tags = append(c.tags, name)
return c
}
func (lw LogWrapper) SetLevel(level logutils.LogLevel) {
lw.origLog.SetLevel(level)
}
func (lw LogWrapper) GoString() string {
return fmt.Sprintf("lw: %+v, orig log: %#v", lw, lw.origLog)
}