Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2023-08-11 12:59:09 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2023-08-15 08:19:22 +0300
commit9b2c13df769467811da5e1b958daac59262aa999 (patch)
treec2cf71ae883a07c38ec90d4cb81301044fcef9fd
parent23de79a6461d2e0285d14db58e6051c77b735ca9 (diff)
golangci-lint: Forbid use of standard logrus logger
Forbid the use of the standard logrus logger in favor of using our own logger accessible via the `internal/log` package.
-rw-r--r--.golangci.yml8
-rw-r--r--cmd/gitaly-hooks/hooks.go3
-rw-r--r--internal/log/logger.go2
3 files changed, 13 insertions, 0 deletions
diff --git a/.golangci.yml b/.golangci.yml
index 0d2832821..80720509c 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -13,6 +13,7 @@ linters:
- errcheck
- errname
- exportloopref
+ - forbidigo
- gci
- gitaly-linters
# We use both gofmt and gofumpt because gofumpt doesn't seem to be linting
@@ -67,6 +68,13 @@ linters-settings:
- (io.Closer).Close
- (net.Conn).Close
- (net.Listener).Close
+ forbidigo:
+ forbid:
+ - p: ^logrus\.(Debug,Error,Fatal,Info,Panic,Print,Trace,Warn,Warning)(f|ln)?$
+ msg: Use the logger provided by `log.Default()` or `ctxlogrus.Extract()`.
+ - p: ^logrus\.StandardLogger$
+ msg: Use the logger provided by `log.Default()` or `ctxlogrus.Extract()`.
+ analyze-types: true
paralleltest:
# Ignore missing calls to `t.Parallel()` and only report incorrect uses of it.
ignore-missing: true
diff --git a/cmd/gitaly-hooks/hooks.go b/cmd/gitaly-hooks/hooks.go
index c6c422daa..6d737acd3 100644
--- a/cmd/gitaly-hooks/hooks.go
+++ b/cmd/gitaly-hooks/hooks.go
@@ -215,6 +215,9 @@ func initializeTracing() {
// All stdout and stderr are captured by Gitaly process. They may be sent back to users.
// We don't want to bother them with these redundant logs. As a result, all logs should be
// suppressed while labkit is in initialization phase.
+ //
+ //nolint:forbidigo // LabKit does not allow us to supply our own logger, so we must modify the standard logger
+ // instead.
output := logrus.StandardLogger().Out
logrus.SetOutput(io.Discard)
defer logrus.SetOutput(output)
diff --git a/internal/log/logger.go b/internal/log/logger.go
index f254bc273..fd45e3676 100644
--- a/internal/log/logger.go
+++ b/internal/log/logger.go
@@ -42,6 +42,8 @@ func UTCTextFormatter() logrus.Formatter {
// `logrus.Info()`. By default it is configured to log to standard output, but in practice it should be configured via
// a call to `Configure()` after the configuration has been loaded.
var defaultLogger = func() *logrus.Logger {
+ //nolint:forbidigo // We reuse the standard logger such that dependencies which might use logrus are properly
+ // configured, as well.
logger := logrus.StandardLogger()
logger.Out = os.Stdout
return logger