From 0074631e0e23d20266f7670203cdb81a9ad94051 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Tue, 5 Sep 2023 09:16:25 +0200 Subject: [PATCH 1/2] chore: use bklog instead of logrus Co-authored-by: Justin Chadwell Signed-off-by: CrazyMax --- cmd/buildkitd/main.go | 4 ++-- executor/resources/monitor.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/buildkitd/main.go b/cmd/buildkitd/main.go index 25a4bb431c4d..3375c438a18c 100644 --- a/cmd/buildkitd/main.go +++ b/cmd/buildkitd/main.go @@ -285,7 +285,7 @@ func main() { // Stop if we are registering or unregistering against Windows SCM. stop, err := registerUnregisterService(cfg.Root) if err != nil { - logrus.Fatal(err) + bklog.L.Fatal(err) } if stop { return nil @@ -332,7 +332,7 @@ func main() { // Launch as a Windows Service if necessary if err := launchService(server); err != nil { - logrus.Fatal(err) + bklog.L.Fatal(err) } errCh := make(chan error, 1) diff --git a/executor/resources/monitor.go b/executor/resources/monitor.go index 95b954bcbe6f..25a53f280671 100644 --- a/executor/resources/monitor.go +++ b/executor/resources/monitor.go @@ -11,9 +11,9 @@ import ( "time" "github.com/moby/buildkit/executor/resources/types" + "github.com/moby/buildkit/util/bklog" "github.com/moby/buildkit/util/network" "github.com/prometheus/procfs" - "github.com/sirupsen/logrus" ) const ( @@ -229,7 +229,7 @@ func NewMonitor() (*Monitor, error) { return } if err := prepareCgroupControllers(); err != nil { - logrus.Warnf("failed to prepare cgroup controllers: %+v", err) + bklog.L.Warnf("failed to prepare cgroup controllers: %+v", err) } }) @@ -280,7 +280,7 @@ func prepareCgroupControllers() error { } if err := os.WriteFile(filepath.Join(defaultMountpoint, cgroupSubtreeFile), []byte("+"+c), 0); err != nil { // ignore error - logrus.Warnf("failed to enable cgroup controller %q: %+v", c, err) + bklog.L.Warnf("failed to enable cgroup controller %q: %+v", c, err) } } return nil From 9d46cfe8e57283156bcfa3d8910ca32f8304a594 Mon Sep 17 00:00:00 2001 From: Justin Chadwell Date: Tue, 5 Sep 2023 11:59:27 +0100 Subject: [PATCH 2/2] lint: fix linting rules for logrus The regexp should only match *symbols*, so we need to remove the opening bracket of the function call. Additionally, we need to use anchors to match the whole string, so as to not break on logrus.TraceLevel and similar. Finally, the error message is reworded to also mention bklog.L. Signed-off-by: Justin Chadwell --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 56984f645703..4c1f6e0784d4 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -39,7 +39,7 @@ linters-settings: forbidigo: forbid: - '^fmt\.Errorf(# use errors\.Errorf instead)?$' - - 'logrus\.(Trace|Debug|Info|Warn|Warning|Error|Fatal)(f|ln)?\((# use bklog\.G\(ctx\) instead of logrus directly)?' + - '^logrus\.(Trace|Debug|Info|Warn|Warning|Error|Fatal)(f|ln)?(# use bklog\.G or bklog\.L instead of logrus directly)?$' importas: alias: - pkg: "github.com/opencontainers/image-spec/specs-go/v1"