Skip to content

Commit e8e3c58

Browse files
authored
Merge pull request #2543 from TinaMor/replace-logrus-package
[Chore] 2523: Use https://github.com/containerd/log for logging
2 parents 657164d + 63d446f commit e8e3c58

File tree

118 files changed

+525
-542
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+525
-542
lines changed

cmd/nerdctl/builder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import (
2222
"os/exec"
2323
"strings"
2424

25+
"github.com/containerd/log"
2526
"github.com/containerd/nerdctl/pkg/buildkitutil"
2627
"github.com/containerd/nerdctl/pkg/defaults"
27-
"github.com/sirupsen/logrus"
2828
"github.com/spf13/cobra"
2929
)
3030

@@ -75,7 +75,7 @@ func builderPruneAction(cmd *cobra.Command, _ []string) error {
7575
}
7676
buildctlArgs := buildkitutil.BuildctlBaseArgs(buildkitHost)
7777
buildctlArgs = append(buildctlArgs, "prune")
78-
logrus.Debugf("running %s %v", buildctlBinary, buildctlArgs)
78+
log.L.Debugf("running %s %v", buildctlBinary, buildctlArgs)
7979
buildctlCmd := exec.Command(buildctlBinary, buildctlArgs...)
8080
buildctlCmd.Env = os.Environ()
8181
buildctlCmd.Stdout = cmd.OutOrStdout()

cmd/nerdctl/compose_ps.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ import (
2727
"github.com/containerd/containerd/errdefs"
2828
"github.com/containerd/containerd/runtime/restart"
2929
gocni "github.com/containerd/go-cni"
30+
"github.com/containerd/log"
3031
"github.com/containerd/nerdctl/pkg/clientutil"
3132
"github.com/containerd/nerdctl/pkg/cmd/compose"
3233
"github.com/containerd/nerdctl/pkg/containerutil"
3334
"github.com/containerd/nerdctl/pkg/formatter"
3435
"github.com/containerd/nerdctl/pkg/labels"
3536
"github.com/containerd/nerdctl/pkg/portutil"
36-
"github.com/sirupsen/logrus"
3737
"github.com/spf13/cobra"
3838
"golang.org/x/sync/errgroup"
3939
)
@@ -335,7 +335,7 @@ func formatPublishers(labelMap map[string]string) []PortPublisher {
335335
dockerPorts = append(dockerPorts, mapper(p))
336336
}
337337
} else {
338-
logrus.Error(err.Error())
338+
log.L.Error(err.Error())
339339
}
340340
return dockerPorts
341341
}

cmd/nerdctl/compose_run_linux_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ import (
2323
"testing"
2424
"time"
2525

26+
"github.com/containerd/log"
2627
"github.com/containerd/nerdctl/pkg/testutil"
2728
"github.com/containerd/nerdctl/pkg/testutil/nettestutil"
2829
"github.com/containerd/nerdctl/pkg/testutil/testregistry"
29-
"github.com/sirupsen/logrus"
3030
"gotest.tools/v3/assert"
3131
)
3232

@@ -94,7 +94,7 @@ services:
9494
stdoutContent := result.Stdout() + result.Stderr()
9595
assert.Assert(psCmd.Base.T, result.ExitCode == 0, stdoutContent)
9696
if strings.Contains(stdoutContent, containerName) {
97-
logrus.Errorf("test failed, the container %s is not removed", stdoutContent)
97+
log.L.Errorf("test failed, the container %s is not removed", stdoutContent)
9898
t.Fail()
9999
return
100100
}
@@ -316,7 +316,7 @@ services:
316316

317317
container := base.InspectContainer(containerName)
318318
if container.Config == nil {
319-
logrus.Errorf("test failed, cannot fetch container config")
319+
log.L.Errorf("test failed, cannot fetch container config")
320320
t.Fail()
321321
}
322322
assert.Equal(t, container.Config.Labels["foo"], "rab")

cmd/nerdctl/compose_up_linux_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ import (
2424
"testing"
2525
"time"
2626

27+
"github.com/containerd/log"
2728
"github.com/containerd/nerdctl/pkg/composer/serviceparser"
2829
"github.com/containerd/nerdctl/pkg/rootlessutil"
2930
"github.com/docker/go-connections/nat"
30-
"github.com/sirupsen/logrus"
3131

3232
"github.com/containerd/nerdctl/pkg/testutil"
3333
"github.com/containerd/nerdctl/pkg/testutil/nettestutil"
@@ -194,7 +194,7 @@ networks:
194194
stdoutContent := result.Stdout() + result.Stderr()
195195
assert.Assert(inspectCmd.Base.T, result.ExitCode == 0, stdoutContent)
196196
if !strings.Contains(stdoutContent, staticIP) {
197-
logrus.Errorf("test failed, the actual container ip is %s", stdoutContent)
197+
log.L.Errorf("test failed, the actual container ip is %s", stdoutContent)
198198
t.Fail()
199199
return
200200
}

cmd/nerdctl/container_run.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"runtime"
2323

2424
"github.com/containerd/console"
25+
"github.com/containerd/log"
2526
"github.com/containerd/nerdctl/pkg/api/types"
2627
"github.com/containerd/nerdctl/pkg/clientutil"
2728
"github.com/containerd/nerdctl/pkg/cmd/container"
@@ -34,7 +35,6 @@ import (
3435
"github.com/containerd/nerdctl/pkg/netutil"
3536
"github.com/containerd/nerdctl/pkg/signalutil"
3637
"github.com/containerd/nerdctl/pkg/taskutil"
37-
"github.com/sirupsen/logrus"
3838
"github.com/spf13/cobra"
3939
)
4040

@@ -348,11 +348,11 @@ func runAction(cmd *cobra.Command, args []string) error {
348348
// network setup/cleanup from the main nerdctl executable.
349349
if runtime.GOOS == "windows" {
350350
if err := netManager.CleanupNetworking(ctx, c); err != nil {
351-
logrus.Warnf("failed to clean up container networking: %s", err)
351+
log.L.Warnf("failed to clean up container networking: %s", err)
352352
}
353353
}
354354
if err := container.RemoveContainer(ctx, c, createOpt.GOptions, true, true, client); err != nil {
355-
logrus.WithError(err).Warnf("failed to remove container %s", id)
355+
log.L.WithError(err).Warnf("failed to remove container %s", id)
356356
}
357357
}()
358358
}
@@ -387,7 +387,7 @@ func runAction(cmd *cobra.Command, args []string) error {
387387
}
388388
if createOpt.TTY {
389389
if err := consoleutil.HandleConsoleResize(ctx, task, con); err != nil {
390-
logrus.WithError(err).Error("console resize")
390+
log.L.WithError(err).Error("console resize")
391391
}
392392
} else {
393393
sigC := signalutil.ForwardAllSignals(ctx, task)
@@ -415,7 +415,7 @@ func runAction(cmd *cobra.Command, args []string) error {
415415
case status := <-statusC:
416416
if createOpt.Rm {
417417
if _, taskDeleteErr := task.Delete(ctx); taskDeleteErr != nil {
418-
logrus.Error(taskDeleteErr)
418+
log.L.Error(taskDeleteErr)
419419
}
420420
}
421421
code, _, err := status.Result()

cmd/nerdctl/container_update.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import (
3636
"github.com/containerd/typeurl/v2"
3737
"github.com/docker/go-units"
3838
runtimespec "github.com/opencontainers/runtime-spec/specs-go"
39-
"github.com/sirupsen/logrus"
4039
"github.com/spf13/cobra"
4140
)
4241

@@ -196,7 +195,7 @@ func getUpdateOption(cmd *cobra.Command, globalOptions types.GlobalCommandOption
196195
return options, err
197196
}
198197
if kernelMemStr != "" && cmd.Flag("kernel-memory").Changed {
199-
logrus.Warnf("The --kernel-memory flag is no longer supported. This flag is a noop.")
198+
log.L.Warnf("The --kernel-memory flag is no longer supported. This flag is a noop.")
200199
}
201200
cpuset, err := cmd.Flags().GetString("cpuset-cpus")
202201
if err != nil {

cmd/nerdctl/image_history.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ import (
2929

3030
"github.com/containerd/containerd"
3131
"github.com/containerd/containerd/pkg/progress"
32+
"github.com/containerd/log"
3233
"github.com/containerd/nerdctl/pkg/clientutil"
3334
"github.com/containerd/nerdctl/pkg/formatter"
3435
"github.com/containerd/nerdctl/pkg/idutil/imagewalker"
3536
"github.com/containerd/nerdctl/pkg/imgutil"
3637
"github.com/opencontainers/image-spec/identity"
37-
"github.com/sirupsen/logrus"
3838
"github.com/spf13/cobra"
3939
)
4040

@@ -198,7 +198,7 @@ func printHistory(cmd *cobra.Command, historys []historyPrintable) error {
198198

199199
for index := len(historys) - 1; index >= 0; index-- {
200200
if err := printer.printHistory(historys[index]); err != nil {
201-
logrus.Warn(err)
201+
log.L.Warn(err)
202202
}
203203
}
204204

cmd/nerdctl/login.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ import (
2121
"io"
2222
"strings"
2323

24+
"github.com/containerd/log"
2425
"github.com/containerd/nerdctl/pkg/api/types"
2526
"github.com/containerd/nerdctl/pkg/cmd/login"
2627

27-
"github.com/sirupsen/logrus"
2828
"github.com/spf13/cobra"
2929
)
3030

@@ -76,7 +76,7 @@ func loginAction(cmd *cobra.Command, args []string) error {
7676
// copied from github.com/docker/cli/cli/command/registry/login.go (v20.10.3)
7777
func verifyLoginOptions(cmd *cobra.Command, options *loginOptions) error {
7878
if options.password != "" {
79-
logrus.Warn("WARNING! Using --password via the CLI is insecure. Use --password-stdin.")
79+
log.L.Warn("WARNING! Using --password via the CLI is insecure. Use --password-stdin.")
8080
if options.passwordStdin {
8181
return errors.New("--password and --password-stdin are mutually exclusive")
8282
}

cmd/nerdctl/main.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"strings"
2626
"time"
2727

28+
"github.com/containerd/log"
2829
"github.com/containerd/nerdctl/pkg/config"
2930
ncdefaults "github.com/containerd/nerdctl/pkg/defaults"
3031
"github.com/containerd/nerdctl/pkg/errutil"
@@ -34,7 +35,6 @@ import (
3435
"github.com/fatih/color"
3536
"github.com/pelletier/go-toml/v2"
3637

37-
"github.com/sirupsen/logrus"
3838
"github.com/spf13/cobra"
3939
"github.com/spf13/pflag"
4040
)
@@ -118,7 +118,7 @@ func usage(c *cobra.Command) error {
118118
func main() {
119119
if err := xmain(); err != nil {
120120
errutil.HandleExitCoder(err)
121-
logrus.Fatal(err)
121+
log.L.Fatal(err)
122122
}
123123
}
124124

@@ -139,15 +139,15 @@ func xmain() error {
139139
func initRootCmdFlags(rootCmd *cobra.Command, tomlPath string) (*pflag.FlagSet, error) {
140140
cfg := config.New()
141141
if r, err := os.Open(tomlPath); err == nil {
142-
logrus.Debugf("Loading config from %q", tomlPath)
142+
log.L.Debugf("Loading config from %q", tomlPath)
143143
defer r.Close()
144144
dec := toml.NewDecoder(r).DisallowUnknownFields() // set Strict to detect typo
145145
if err := dec.Decode(cfg); err != nil {
146146
return nil, fmt.Errorf("failed to load nerdctl config (not daemon config) from %q (Hint: don't mix up daemon's `config.toml` with `nerdctl.toml`): %w", tomlPath, err)
147147
}
148-
logrus.Debugf("Loaded config %+v", cfg)
148+
log.L.Debugf("Loaded config %+v", cfg)
149149
} else {
150-
logrus.WithError(err).Debugf("Not loading config from %q", tomlPath)
150+
log.L.WithError(err).Debugf("Not loading config from %q", tomlPath)
151151
if !errors.Is(err, os.ErrNotExist) {
152152
return nil, err
153153
}
@@ -216,7 +216,7 @@ Config file ($NERDCTL_TOML): %s
216216
debug = globalOptions.Debug
217217
}
218218
if debug {
219-
logrus.SetLevel(logrus.DebugLevel)
219+
log.SetLevel(log.DebugLevel.String())
220220
}
221221
address := globalOptions.Address
222222
if strings.Contains(address, "://") && !strings.HasPrefix(address, "unix://") {
@@ -327,7 +327,7 @@ Config file ($NERDCTL_TOML): %s
327327
func globalFlags(cmd *cobra.Command) (string, []string) {
328328
args0, err := os.Executable()
329329
if err != nil {
330-
logrus.WithError(err).Warnf("cannot call os.Executable(), assuming the executable to be %q", os.Args[0])
330+
log.L.WithError(err).Warnf("cannot call os.Executable(), assuming the executable to be %q", os.Args[0])
331331
args0 = os.Args[0]
332332
}
333333
if len(os.Args) < 2 {
@@ -396,7 +396,7 @@ func AddIntFlag(cmd *cobra.Command, name string, aliases []string, value int, en
396396
if envV, ok := os.LookupEnv(env); ok {
397397
v, err := strconv.ParseInt(envV, 10, 64)
398398
if err != nil {
399-
logrus.WithError(err).Warnf("Invalid int value for `%s`", env)
399+
log.L.WithError(err).Warnf("Invalid int value for `%s`", env)
400400
}
401401
value = int(v)
402402
}
@@ -423,7 +423,7 @@ func AddDurationFlag(cmd *cobra.Command, name string, aliases []string, value ti
423423
var err error
424424
value, err = time.ParseDuration(envV)
425425
if err != nil {
426-
logrus.WithError(err).Warnf("Invalid duration value for `%s`", env)
426+
log.L.WithError(err).Warnf("Invalid duration value for `%s`", env)
427427
}
428428
}
429429
aliasesUsage := fmt.Sprintf("Alias of --%s", name)
@@ -501,7 +501,7 @@ func AddPersistentBoolFlag(cmd *cobra.Command, name string, aliases, nonPersiste
501501
var err error
502502
value, err = strconv.ParseBool(envV)
503503
if err != nil {
504-
logrus.WithError(err).Warnf("Invalid boolean value for `%s`", env)
504+
log.L.WithError(err).Warnf("Invalid boolean value for `%s`", env)
505505
}
506506
}
507507
aliasesUsage := fmt.Sprintf("Alias of --%s", name)

cmd/nerdctl/main_unix.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
package main
2020

2121
import (
22+
"github.com/containerd/log"
2223
"github.com/containerd/nerdctl/pkg/clientutil"
2324
"github.com/containerd/nerdctl/pkg/infoutil"
2425
"github.com/containerd/nerdctl/pkg/rootlessutil"
25-
"github.com/sirupsen/logrus"
2626
"github.com/spf13/cobra"
2727
)
2828

@@ -46,7 +46,7 @@ func shellCompleteNamespaceNames(cmd *cobra.Command, args []string, toComplete s
4646
nsService := client.NamespaceService()
4747
nsList, err := nsService.List(ctx)
4848
if err != nil {
49-
logrus.Warn(err)
49+
log.L.Warn(err)
5050
return nil, cobra.ShellCompDirectiveError
5151
}
5252
var candidates []string

0 commit comments

Comments
 (0)