From 61c09743232cc35241d06db53795ebf3777131cd Mon Sep 17 00:00:00 2001
From: Denis Isaev <denis@golangci.com>
Date: Fri, 8 Jun 2018 08:43:43 +0300
Subject: [PATCH] improved warnings logging

---
 pkg/commands/run_config.go |  7 ++++---
 pkg/golinters/gas.go       |  4 ++--
 pkg/golinters/golint.go    |  4 ++--
 pkg/lint/runner.go         |  7 ++++---
 pkg/logutils/logutils.go   | 17 +++++++++++++++++
 5 files changed, 29 insertions(+), 10 deletions(-)
 create mode 100644 pkg/logutils/logutils.go

diff --git a/pkg/commands/run_config.go b/pkg/commands/run_config.go
index 4aa2bb4f..20b8bf91 100644
--- a/pkg/commands/run_config.go
+++ b/pkg/commands/run_config.go
@@ -9,6 +9,7 @@ import (
 
 	"github.com/golangci/golangci-lint/pkg/config"
 	"github.com/golangci/golangci-lint/pkg/fsutils"
+	"github.com/golangci/golangci-lint/pkg/logutils"
 	"github.com/golangci/golangci-lint/pkg/printers"
 	"github.com/sirupsen/logrus"
 	"github.com/spf13/pflag"
@@ -83,7 +84,7 @@ func setupConfigFileSearch(args []string) {
 
 	absStartPath, err := filepath.Abs(firstArg)
 	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)
 	}
 
@@ -116,13 +117,13 @@ func setupConfigFileSearch(args []string) {
 func getRelPath(p string) string {
 	wd, err := os.Getwd()
 	if err != nil {
-		logrus.Infof("Can't get wd: %s", err)
+		logutils.HiddenWarnf("Can't get wd: %s", err)
 		return p
 	}
 
 	r, err := filepath.Rel(wd, p)
 	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
 	}
 
diff --git a/pkg/golinters/gas.go b/pkg/golinters/gas.go
index c5ecd033..75d9a727 100644
--- a/pkg/golinters/gas.go
+++ b/pkg/golinters/gas.go
@@ -11,8 +11,8 @@ import (
 	"github.com/GoASTScanner/gas"
 	"github.com/GoASTScanner/gas/rules"
 	"github.com/golangci/golangci-lint/pkg/lint/linter"
+	"github.com/golangci/golangci-lint/pkg/logutils"
 	"github.com/golangci/golangci-lint/pkg/result"
-	"github.com/sirupsen/logrus"
 )
 
 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)
 		if err != nil {
 			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
 			}
 			line = r.From
diff --git a/pkg/golinters/golint.go b/pkg/golinters/golint.go
index 1d5f5476..76ff23cb 100644
--- a/pkg/golinters/golint.go
+++ b/pkg/golinters/golint.go
@@ -7,8 +7,8 @@ import (
 
 	lintAPI "github.com/golang/lint"
 	"github.com/golangci/golangci-lint/pkg/lint/linter"
+	"github.com/golangci/golangci-lint/pkg/logutils"
 	"github.com/golangci/golangci-lint/pkg/result"
-	"github.com/sirupsen/logrus"
 )
 
 type Golint struct{}
@@ -33,7 +33,7 @@ func (g Golint) Run(ctx context.Context, lintCtx *linter.Context) ([]result.Issu
 		issues = append(issues, i...)
 	}
 	if lintErr != nil {
-		logrus.Infof("golint: %s", lintErr)
+		logutils.HiddenWarnf("golint: %s", lintErr)
 	}
 
 	return issues, nil
diff --git a/pkg/lint/runner.go b/pkg/lint/runner.go
index 594cff4b..e15afc74 100644
--- a/pkg/lint/runner.go
+++ b/pkg/lint/runner.go
@@ -10,6 +10,7 @@ import (
 	"time"
 
 	"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/processors"
 	"github.com/golangci/golangci-lint/pkg/timeutils"
@@ -30,7 +31,7 @@ func runLinterSafe(ctx context.Context, lintCtx *linter.Context, lc linter.Confi
 	defer func() {
 		if panicData := recover(); panicData != nil {
 			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 {
 			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
 			}
 
@@ -220,7 +221,7 @@ func (r *SimpleRunner) processIssues(ctx context.Context, issues []result.Issue,
 		})
 
 		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 {
 			issues = newIssues
 		}
diff --git a/pkg/logutils/logutils.go b/pkg/logutils/logutils.go
new file mode 100644
index 00000000..4661bd5f
--- /dev/null
+++ b/pkg/logutils/logutils.go
@@ -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...)
+	}
+}