Skip to content

Commit

Permalink
replace direct uses of logrus for containerd/log
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastiaan van Stijn <[email protected]>
  • Loading branch information
thaJeztah committed Jun 12, 2024
1 parent 872935f commit d147de2
Show file tree
Hide file tree
Showing 36 changed files with 133 additions and 125 deletions.
4 changes: 2 additions & 2 deletions cli-plugins/manager/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"encoding/json"
"strings"

"github.com/containerd/log"
"github.com/docker/cli/cli-plugins/hooks"
"github.com/docker/cli/cli/command"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
Expand Down Expand Up @@ -105,7 +105,7 @@ func invokeAndCollectHooks(ctx context.Context, dockerCli command.Cli, rootCmd,
var appended bool
nextSteps, appended = appendNextSteps(nextSteps, processedHook)
if !appended {
logrus.Debugf("Plugin %s responded with an empty hook message %q. Ignoring.", pluginName, string(hookReturn))
log.G(ctx).Debugf("Plugin %s responded with an empty hook message %q. Ignoring.", pluginName, string(hookReturn))
}
}
return nextSteps
Expand Down
6 changes: 3 additions & 3 deletions cli-plugins/socket/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"runtime"
"sync"

"github.com/sirupsen/logrus"
"github.com/containerd/log"
)

// EnvKey represents the well-known environment variable used to pass the
Expand All @@ -32,7 +32,7 @@ func NewPluginServer(h func(net.Conn)) (*PluginServer, error) {
if err != nil {
return nil, err
}
logrus.Trace("Plugin server listening on ", l.Addr())
log.L.Logger.Trace("Plugin server listening on ", l.Addr())

if h == nil {
h = func(net.Conn) {}
Expand Down Expand Up @@ -95,7 +95,7 @@ func (pl *PluginServer) Addr() net.Addr {
//
// The error value is that of the underlying [net.Listner.Close] call.
func (pl *PluginServer) Close() error {
logrus.Trace("Closing plugin server")
log.L.Logger.Trace("Closing plugin server")
// Close connections first to ensure the connections get io.EOF instead
// of a connection reset.
pl.closeAllConns()
Expand Down
4 changes: 2 additions & 2 deletions cli/command/container/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"io"

"github.com/containerd/log"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
Expand All @@ -12,7 +13,6 @@ import (
"github.com/docker/docker/client"
"github.com/moby/sys/signal"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -180,6 +180,6 @@ func resizeTTY(ctx context.Context, dockerCli command.Cli, containerID string) {
// After the above resizing occurs, the call to MonitorTtySize below will handle resetting back
// to the actual size.
if err := MonitorTtySize(ctx, dockerCli, containerID, false); err != nil {
logrus.Debugf("Error monitoring TTY size: %s", err)
log.G(ctx).Debugf("Error monitoring TTY size: %s", err)
}
}
4 changes: 2 additions & 2 deletions cli/command/container/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"os"

"github.com/containerd/log"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
Expand All @@ -15,7 +16,6 @@ import (
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -198,7 +198,7 @@ func interactiveExec(ctx context.Context, dockerCli command.Cli, execOptions *co
}

if err := <-errCh; err != nil {
logrus.Debugf("Error hijack: %s", err)
log.G(ctx).Debugf("Error hijack: %s", err)
return err
}

Expand Down
14 changes: 7 additions & 7 deletions cli/command/container/hijack.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
"runtime"
"sync"

"github.com/containerd/log"
"github.com/docker/cli/cli/command"
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/pkg/stdcopy"
"github.com/moby/term"
"github.com/sirupsen/logrus"
)

// The default escape key sequence: ctrl-p, ctrl-q
Expand Down Expand Up @@ -97,7 +97,7 @@ func (h *hijackedIOStreamer) setupInput() (restore func(), err error) {
if h.detachKeys != "" {
customEscapeKeys, err := term.ToBytes(h.detachKeys)
if err != nil {
logrus.Warnf("invalid detach escape keys, using default: %s", err)
log.G(context.TODO()).Warnf("invalid detach escape keys, using default: %s", err)
} else {
escapeKeys = customEscapeKeys
}
Expand Down Expand Up @@ -129,10 +129,10 @@ func (h *hijackedIOStreamer) beginOutputStream(restoreInput func()) <-chan error
_, err = stdcopy.StdCopy(h.outputStream, h.errorStream, h.resp.Reader)
}

logrus.Debug("[hijack] End of stdout")
log.G(context.TODO()).Debug("[hijack] End of stdout")

if err != nil {
logrus.Debugf("Error receiveStdout: %s", err)
log.G(context.TODO()).Debugf("Error receiveStdout: %s", err)
}

outputDone <- err
Expand All @@ -153,7 +153,7 @@ func (h *hijackedIOStreamer) beginInputStream(restoreInput func()) (doneC <-chan
// messages will be in normal type.
restoreInput()

logrus.Debug("[hijack] End of stdin")
log.G(context.TODO()).Debug("[hijack] End of stdin")

if _, ok := err.(term.EscapeError); ok {
detached <- err
Expand All @@ -164,12 +164,12 @@ func (h *hijackedIOStreamer) beginInputStream(restoreInput func()) (doneC <-chan
// This error will also occur on the receive
// side (from stdout) where it will be
// propagated back to the caller.
logrus.Debugf("Error sendStdin: %s", err)
log.G(context.TODO()).Debugf("Error sendStdin: %s", err)
}
}

if err := h.resp.CloseWrite(); err != nil {
logrus.Debugf("Couldn't send EOF: %s", err)
log.G(context.TODO()).Debugf("Couldn't send EOF: %s", err)
}

close(inputDone)
Expand Down
5 changes: 3 additions & 2 deletions cli/command/container/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package container

import (
"bytes"
"context"
"encoding/json"
"fmt"
"os"
Expand All @@ -13,6 +14,7 @@ import (
"strings"
"time"

"github.com/containerd/log"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/compose/loader"
"github.com/docker/cli/opts"
Expand All @@ -23,7 +25,6 @@ import (
"github.com/docker/docker/errdefs"
"github.com/docker/go-connections/nat"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/pflag"
cdi "tags.cncf.io/container-device-interface/pkg/parser"
)
Expand Down Expand Up @@ -366,7 +367,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con

mounts := copts.mounts.Value()
if len(mounts) > 0 && copts.volumeDriver != "" {
logrus.Warn("`--volume-driver` is ignored for volumes specified via `--mount`. Use `--mount type=volume,volume-driver=...` instead.")
log.G(context.TODO()).Warn("`--volume-driver` is ignored for volumes specified via `--mount`. Use `--mount type=volume,volume-driver=...` instead.")
}
var binds []string
volumes := copts.volumes.GetMap()
Expand Down
4 changes: 2 additions & 2 deletions cli/command/container/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
"syscall"

"github.com/containerd/log"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
Expand All @@ -16,7 +17,6 @@ import (
"github.com/moby/sys/signal"
"github.com/moby/term"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
Expand Down Expand Up @@ -228,7 +228,7 @@ func runContainer(ctx context.Context, dockerCli command.Cli, runOpts *runOption
return nil
}

logrus.Debugf("Error hijack: %s", err)
log.G(ctx).Debugf("Error hijack: %s", err)
return err
}
}
Expand Down
4 changes: 2 additions & 2 deletions cli/command/container/signals.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"os"
gosignal "os/signal"

"github.com/containerd/log"
"github.com/docker/docker/client"
"github.com/moby/sys/signal"
"github.com/sirupsen/logrus"
)

// ForwardAllSignals forwards signals to the container
Expand Down Expand Up @@ -49,7 +49,7 @@ func ForwardAllSignals(ctx context.Context, apiClient client.ContainerAPIClient,
}

if err := apiClient.ContainerKill(ctx, cid, sig); err != nil {
logrus.Debugf("Error sending signal: %s", err)
log.G(ctx).Debugf("Error sending signal: %s", err)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions cli/command/container/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"sync"
"time"

"github.com/containerd/log"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
Expand All @@ -17,7 +18,6 @@ import (
"github.com/docker/docker/api/types/events"
"github.com/docker/docker/api/types/filters"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -337,7 +337,7 @@ func (eh *eventHandler) watch(c <-chan events.Message) {
if !exists {
continue
}
logrus.Debugf("event handler: received event: %v", e)
log.G(context.TODO()).Debugf("event handler: received event: %v", e)
go h(e)
}
}
4 changes: 2 additions & 2 deletions cli/command/container/stats_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"sync"
"time"

"github.com/containerd/log"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

type stats struct {
Expand Down Expand Up @@ -51,7 +51,7 @@ func (s *stats) isKnownContainer(cid string) (int, bool) {
}

func collect(ctx context.Context, s *Stats, cli client.APIClient, streamStats bool, waitFirst *sync.WaitGroup) {
logrus.Debugf("collecting stats for %s", s.Container)
log.G(ctx).Debugf("collecting stats for %s", s.Container)
var (
getFirst bool
previousCPU uint64
Expand Down
4 changes: 2 additions & 2 deletions cli/command/container/tty.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
"runtime"
"time"

"github.com/containerd/log"
"github.com/docker/cli/cli/command"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
"github.com/moby/sys/signal"
"github.com/sirupsen/logrus"
)

// resizeTtyTo resizes tty to specific height and width
Expand All @@ -34,7 +34,7 @@ func resizeTtyTo(ctx context.Context, apiClient client.ContainerAPIClient, id st
}

if err != nil {
logrus.Debugf("Error resize: %s\r", err)
log.G(ctx).Debugf("Error resize: %s\r", err)
}
return err
}
Expand Down
12 changes: 6 additions & 6 deletions cli/command/container/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"errors"
"strconv"

"github.com/containerd/log"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/events"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/client"
"github.com/sirupsen/logrus"
)

func waitExitOrRemoved(ctx context.Context, apiClient client.APIClient, containerID string, waitRemove bool) <-chan int {
Expand Down Expand Up @@ -41,7 +41,7 @@ func waitExitOrRemoved(ctx context.Context, apiClient client.APIClient, containe
return
case result := <-resultC:
if result.Error != nil {
logrus.Errorf("Error waiting for container: %v", result.Error.Message)
log.G(ctx).Errorf("Error waiting for container: %v", result.Error.Message)
statusC <- 125
} else {
statusC <- int(result.StatusCode)
Expand All @@ -50,7 +50,7 @@ func waitExitOrRemoved(ctx context.Context, apiClient client.APIClient, containe
if errors.Is(err, context.Canceled) {
return
}
logrus.Errorf("error waiting for container: %v", err)
log.G(ctx).Errorf("error waiting for container: %v", err)
statusC <- 125
}
}()
Expand Down Expand Up @@ -80,7 +80,7 @@ func legacyWaitExitOrRemoved(ctx context.Context, apiClient client.APIClient, co
if v, ok := e.Actor.Attributes["exitCode"]; ok {
code, cerr := strconv.Atoi(v)
if cerr != nil {
logrus.Errorf("failed to convert exitcode '%q' to int: %v", v, cerr)
log.G(ctx).Errorf("failed to convert exitcode '%q' to int: %v", v, cerr)
} else {
exitCode = code
}
Expand All @@ -93,7 +93,7 @@ func legacyWaitExitOrRemoved(ctx context.Context, apiClient client.APIClient, co
go func() {
removeErr = apiClient.ContainerRemove(ctx, containerID, container.RemoveOptions{RemoveVolumes: true})
if removeErr != nil {
logrus.Errorf("error removing container: %v", removeErr)
log.G(ctx).Errorf("error removing container: %v", removeErr)
cancel() // cancel the event Q
}
}()
Expand Down Expand Up @@ -124,7 +124,7 @@ func legacyWaitExitOrRemoved(ctx context.Context, apiClient client.APIClient, co
return
}
case err := <-errq:
logrus.Errorf("error getting events from daemon: %v", err)
log.G(eventCtx).Errorf("error getting events from daemon: %v", err)
return
}
}
Expand Down
4 changes: 2 additions & 2 deletions cli/command/image/trust.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"sort"

"github.com/containerd/log"
"github.com/distribution/reference"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/streams"
Expand All @@ -19,7 +20,6 @@ import (
"github.com/docker/docker/registry"
"github.com/opencontainers/go-digest"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/theupdateframework/notary/client"
"github.com/theupdateframework/notary/tuf/data"
)
Expand Down Expand Up @@ -256,7 +256,7 @@ func getTrustedPullTargets(cli command.Cli, imgRefAndAuth trust.ImageRefAndAuth)
return nil, trust.NotaryError(ref.Name(), errors.Errorf("No trust data for %s", tagged.Tag()))
}

logrus.Debugf("retrieving target for %s role", t.Role)
log.G(context.TODO()).Debugf("retrieving target for %s role", t.Role)
r, err := convertTarget(t.Target)
return []target{r}, err
}
Expand Down
Loading

0 comments on commit d147de2

Please sign in to comment.