improved warnings logging

This commit is contained in:
Denis Isaev 2018-06-08 08:43:43 +03:00
parent 1fad9ea1d7
commit 61c0974323
No known key found for this signature in database
GPG Key ID: A36A0EC8E27A1A01
5 changed files with 29 additions and 10 deletions

View File

@ -9,6 +9,7 @@ import (
"github.com/golangci/golangci-lint/pkg/config" "github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/fsutils" "github.com/golangci/golangci-lint/pkg/fsutils"
"github.com/golangci/golangci-lint/pkg/logutils"
"github.com/golangci/golangci-lint/pkg/printers" "github.com/golangci/golangci-lint/pkg/printers"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/spf13/pflag" "github.com/spf13/pflag"
@ -83,7 +84,7 @@ func setupConfigFileSearch(args []string) {
absStartPath, err := filepath.Abs(firstArg) absStartPath, err := filepath.Abs(firstArg)
if err != nil { if err != nil {
logrus.Infof("Can't make abs path for %q: %s", firstArg, err) logutils.HiddenWarnf("Can't make abs path for %q: %s", firstArg, err)
absStartPath = filepath.Clean(firstArg) absStartPath = filepath.Clean(firstArg)
} }
@ -116,13 +117,13 @@ func setupConfigFileSearch(args []string) {
func getRelPath(p string) string { func getRelPath(p string) string {
wd, err := os.Getwd() wd, err := os.Getwd()
if err != nil { if err != nil {
logrus.Infof("Can't get wd: %s", err) logutils.HiddenWarnf("Can't get wd: %s", err)
return p return p
} }
r, err := filepath.Rel(wd, p) r, err := filepath.Rel(wd, p)
if err != nil { if err != nil {
logrus.Infof("Can't make path %s relative to %s: %s", p, wd, err) logutils.HiddenWarnf("Can't make path %s relative to %s: %s", p, wd, err)
return p return p
} }

View File

@ -11,8 +11,8 @@ import (
"github.com/GoASTScanner/gas" "github.com/GoASTScanner/gas"
"github.com/GoASTScanner/gas/rules" "github.com/GoASTScanner/gas/rules"
"github.com/golangci/golangci-lint/pkg/lint/linter" "github.com/golangci/golangci-lint/pkg/lint/linter"
"github.com/golangci/golangci-lint/pkg/logutils"
"github.com/golangci/golangci-lint/pkg/result" "github.com/golangci/golangci-lint/pkg/result"
"github.com/sirupsen/logrus"
) )
type Gas struct{} type Gas struct{}
@ -45,7 +45,7 @@ func (lint Gas) Run(ctx context.Context, lintCtx *linter.Context) ([]result.Issu
line, err := strconv.Atoi(i.Line) line, err := strconv.Atoi(i.Line)
if err != nil { if err != nil {
if n, rerr := fmt.Sscanf(i.Line, "%d-%d", &r.From, &r.To); rerr != nil || n != 2 { if n, rerr := fmt.Sscanf(i.Line, "%d-%d", &r.From, &r.To); rerr != nil || n != 2 {
logrus.Infof("Can't convert gas line number %q of %v to int: %s", i.Line, i, err) logutils.HiddenWarnf("Can't convert gas line number %q of %v to int: %s", i.Line, i, err)
continue continue
} }
line = r.From line = r.From

View File

@ -7,8 +7,8 @@ import (
lintAPI "github.com/golang/lint" lintAPI "github.com/golang/lint"
"github.com/golangci/golangci-lint/pkg/lint/linter" "github.com/golangci/golangci-lint/pkg/lint/linter"
"github.com/golangci/golangci-lint/pkg/logutils"
"github.com/golangci/golangci-lint/pkg/result" "github.com/golangci/golangci-lint/pkg/result"
"github.com/sirupsen/logrus"
) )
type Golint struct{} type Golint struct{}
@ -33,7 +33,7 @@ func (g Golint) Run(ctx context.Context, lintCtx *linter.Context) ([]result.Issu
issues = append(issues, i...) issues = append(issues, i...)
} }
if lintErr != nil { if lintErr != nil {
logrus.Infof("golint: %s", lintErr) logutils.HiddenWarnf("golint: %s", lintErr)
} }
return issues, nil return issues, nil

View File

@ -10,6 +10,7 @@ import (
"time" "time"
"github.com/golangci/golangci-lint/pkg/lint/linter" "github.com/golangci/golangci-lint/pkg/lint/linter"
"github.com/golangci/golangci-lint/pkg/logutils"
"github.com/golangci/golangci-lint/pkg/result" "github.com/golangci/golangci-lint/pkg/result"
"github.com/golangci/golangci-lint/pkg/result/processors" "github.com/golangci/golangci-lint/pkg/result/processors"
"github.com/golangci/golangci-lint/pkg/timeutils" "github.com/golangci/golangci-lint/pkg/timeutils"
@ -30,7 +31,7 @@ func runLinterSafe(ctx context.Context, lintCtx *linter.Context, lc linter.Confi
defer func() { defer func() {
if panicData := recover(); panicData != nil { if panicData := recover(); panicData != nil {
err = fmt.Errorf("panic occured: %s", panicData) err = fmt.Errorf("panic occured: %s", panicData)
logrus.Infof("Panic stack trace: %s", debug.Stack()) logutils.HiddenWarnf("Panic stack trace: %s", debug.Stack())
} }
}() }()
@ -151,7 +152,7 @@ func (r SimpleRunner) processLintResults(ctx context.Context, inCh <-chan lintRe
for res := range inCh { for res := range inCh {
if res.err != nil { if res.err != nil {
logrus.Infof("Can't run linter %s: %s", res.linter.Linter.Name(), res.err) logutils.HiddenWarnf("Can't run linter %s: %s", res.linter.Linter.Name(), res.err)
continue continue
} }
@ -220,7 +221,7 @@ func (r *SimpleRunner) processIssues(ctx context.Context, issues []result.Issue,
}) })
if err != nil { if err != nil {
logrus.Infof("Can't process result by %s processor: %s", p.Name(), err) logutils.HiddenWarnf("Can't process result by %s processor: %s", p.Name(), err)
} else { } else {
issues = newIssues issues = newIssues
} }

17
pkg/logutils/logutils.go Normal file
View File

@ -0,0 +1,17 @@
package logutils
import (
"os"
"github.com/sirupsen/logrus"
)
var isGolangCIRun = os.Getenv("GOLANGCI_COM_RUN") == "1"
func HiddenWarnf(format string, args ...interface{}) {
if isGolangCIRun {
logrus.Warnf(format, args...)
} else {
logrus.Infof(format, args...)
}
}