Browse Source

Make sure we can have a console

Djordje Lukic 5 năm trước cách đây
mục cha
commit
e4354c82d1
1 tập tin đã thay đổi với 9 bổ sung1 xóa
  1. 9 1
      cli/cmd/logs.go

+ 9 - 1
cli/cmd/logs.go

@@ -18,6 +18,8 @@ package cmd
 
 
 import (
 import (
 	"context"
 	"context"
+	"io"
+	"os"
 
 
 	"github.com/containerd/console"
 	"github.com/containerd/console"
 	"github.com/pkg/errors"
 	"github.com/pkg/errors"
@@ -55,11 +57,17 @@ func runLogs(ctx context.Context, containerName string, opts logsOpts) error {
 	if err != nil {
 	if err != nil {
 		return errors.Wrap(err, "cannot connect to backend")
 		return errors.Wrap(err, "cannot connect to backend")
 	}
 	}
+	var con io.Writer
+
+	con = os.Stdout
+	if c, err := console.ConsoleFromFile(os.Stdout); err == nil {
+		con = c
+	}
 
 
 	req := containers.LogsRequest{
 	req := containers.LogsRequest{
 		Follow: opts.Follow,
 		Follow: opts.Follow,
 		Tail:   opts.Tail,
 		Tail:   opts.Tail,
-		Writer: console.Current(),
+		Writer: con,
 	}
 	}
 
 
 	return c.ContainerService().Logs(ctx, containerName, req)
 	return c.ContainerService().Logs(ctx, containerName, req)