Skip to content

Commit 61c0974

Browse files
committed
improved warnings logging
1 parent 1fad9ea commit 61c0974

File tree

5 files changed

+29
-10
lines changed

5 files changed

+29
-10
lines changed

Diff for: pkg/commands/run_config.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/golangci/golangci-lint/pkg/config"
1111
"github.com/golangci/golangci-lint/pkg/fsutils"
12+
"github.com/golangci/golangci-lint/pkg/logutils"
1213
"github.com/golangci/golangci-lint/pkg/printers"
1314
"github.com/sirupsen/logrus"
1415
"github.com/spf13/pflag"
@@ -83,7 +84,7 @@ func setupConfigFileSearch(args []string) {
8384

8485
absStartPath, err := filepath.Abs(firstArg)
8586
if err != nil {
86-
logrus.Infof("Can't make abs path for %q: %s", firstArg, err)
87+
logutils.HiddenWarnf("Can't make abs path for %q: %s", firstArg, err)
8788
absStartPath = filepath.Clean(firstArg)
8889
}
8990

@@ -116,13 +117,13 @@ func setupConfigFileSearch(args []string) {
116117
func getRelPath(p string) string {
117118
wd, err := os.Getwd()
118119
if err != nil {
119-
logrus.Infof("Can't get wd: %s", err)
120+
logutils.HiddenWarnf("Can't get wd: %s", err)
120121
return p
121122
}
122123

123124
r, err := filepath.Rel(wd, p)
124125
if err != nil {
125-
logrus.Infof("Can't make path %s relative to %s: %s", p, wd, err)
126+
logutils.HiddenWarnf("Can't make path %s relative to %s: %s", p, wd, err)
126127
return p
127128
}
128129

Diff for: pkg/golinters/gas.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
"github.com/GoASTScanner/gas"
1212
"github.com/GoASTScanner/gas/rules"
1313
"github.com/golangci/golangci-lint/pkg/lint/linter"
14+
"github.com/golangci/golangci-lint/pkg/logutils"
1415
"github.com/golangci/golangci-lint/pkg/result"
15-
"github.com/sirupsen/logrus"
1616
)
1717

1818
type Gas struct{}
@@ -45,7 +45,7 @@ func (lint Gas) Run(ctx context.Context, lintCtx *linter.Context) ([]result.Issu
4545
line, err := strconv.Atoi(i.Line)
4646
if err != nil {
4747
if n, rerr := fmt.Sscanf(i.Line, "%d-%d", &r.From, &r.To); rerr != nil || n != 2 {
48-
logrus.Infof("Can't convert gas line number %q of %v to int: %s", i.Line, i, err)
48+
logutils.HiddenWarnf("Can't convert gas line number %q of %v to int: %s", i.Line, i, err)
4949
continue
5050
}
5151
line = r.From

Diff for: pkg/golinters/golint.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77

88
lintAPI "github.com/golang/lint"
99
"github.com/golangci/golangci-lint/pkg/lint/linter"
10+
"github.com/golangci/golangci-lint/pkg/logutils"
1011
"github.com/golangci/golangci-lint/pkg/result"
11-
"github.com/sirupsen/logrus"
1212
)
1313

1414
type Golint struct{}
@@ -33,7 +33,7 @@ func (g Golint) Run(ctx context.Context, lintCtx *linter.Context) ([]result.Issu
3333
issues = append(issues, i...)
3434
}
3535
if lintErr != nil {
36-
logrus.Infof("golint: %s", lintErr)
36+
logutils.HiddenWarnf("golint: %s", lintErr)
3737
}
3838

3939
return issues, nil

Diff for: pkg/lint/runner.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/golangci/golangci-lint/pkg/lint/linter"
13+
"github.com/golangci/golangci-lint/pkg/logutils"
1314
"github.com/golangci/golangci-lint/pkg/result"
1415
"github.com/golangci/golangci-lint/pkg/result/processors"
1516
"github.com/golangci/golangci-lint/pkg/timeutils"
@@ -30,7 +31,7 @@ func runLinterSafe(ctx context.Context, lintCtx *linter.Context, lc linter.Confi
3031
defer func() {
3132
if panicData := recover(); panicData != nil {
3233
err = fmt.Errorf("panic occured: %s", panicData)
33-
logrus.Infof("Panic stack trace: %s", debug.Stack())
34+
logutils.HiddenWarnf("Panic stack trace: %s", debug.Stack())
3435
}
3536
}()
3637

@@ -151,7 +152,7 @@ func (r SimpleRunner) processLintResults(ctx context.Context, inCh <-chan lintRe
151152

152153
for res := range inCh {
153154
if res.err != nil {
154-
logrus.Infof("Can't run linter %s: %s", res.linter.Linter.Name(), res.err)
155+
logutils.HiddenWarnf("Can't run linter %s: %s", res.linter.Linter.Name(), res.err)
155156
continue
156157
}
157158

@@ -220,7 +221,7 @@ func (r *SimpleRunner) processIssues(ctx context.Context, issues []result.Issue,
220221
})
221222

222223
if err != nil {
223-
logrus.Infof("Can't process result by %s processor: %s", p.Name(), err)
224+
logutils.HiddenWarnf("Can't process result by %s processor: %s", p.Name(), err)
224225
} else {
225226
issues = newIssues
226227
}

Diff for: pkg/logutils/logutils.go

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package logutils
2+
3+
import (
4+
"os"
5+
6+
"github.com/sirupsen/logrus"
7+
)
8+
9+
var isGolangCIRun = os.Getenv("GOLANGCI_COM_RUN") == "1"
10+
11+
func HiddenWarnf(format string, args ...interface{}) {
12+
if isGolangCIRun {
13+
logrus.Warnf(format, args...)
14+
} else {
15+
logrus.Infof(format, args...)
16+
}
17+
}

0 commit comments

Comments
 (0)