From 52655916c6b37766b62006c5bdc5460a0a874f93 Mon Sep 17 00:00:00 2001 From: guillaume Date: Wed, 2 Mar 2022 12:13:26 +0100 Subject: [PATCH] Windows escape sequence fix Our logger wasn't entirely compatible with Windows escape sequences when not in TTY mode. This fix changes the stderr to one that automatically transforms the escape sequences to some Windows compatible ones. Signed-off-by: guillaume --- cmd/dagger/logger/logger.go | 3 ++- go.mod | 1 + go.sum | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/dagger/logger/logger.go b/cmd/dagger/logger/logger.go index 795a8938..f9761816 100644 --- a/cmd/dagger/logger/logger.go +++ b/cmd/dagger/logger/logger.go @@ -9,6 +9,7 @@ import ( "fmt" "os" + "github.com/mattn/go-colorable" "github.com/rs/zerolog" "github.com/spf13/viper" "golang.org/x/term" @@ -22,7 +23,7 @@ func New() zerolog.Logger { Logger() if !jsonLogs() { - logger = logger.Output(&PlainOutput{Out: os.Stderr}) + logger = logger.Output(&PlainOutput{Out: colorable.NewColorableStderr()}) } else { logger = logger.With().Timestamp().Caller().Logger() } diff --git a/go.mod b/go.mod index a50580c9..5101eb26 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,7 @@ require ( github.com/gofrs/flock v0.8.1 github.com/google/uuid v1.3.0 github.com/hashicorp/go-version v1.4.0 + github.com/mattn/go-colorable v0.1.6 github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db github.com/mitchellh/go-homedir v1.1.0 github.com/moby/buildkit v0.10.0-rc2 diff --git a/go.sum b/go.sum index c5210c42..f04f7999 100644 --- a/go.sum +++ b/go.sum @@ -964,6 +964,7 @@ github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaO github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE= github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-ieproxy v0.0.0-20190610004146-91bb50d98149/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc= github.com/mattn/go-ieproxy v0.0.0-20190702010315-6dee0af9227d/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc= @@ -973,6 +974,7 @@ github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNx github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= +github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-shellwords v1.0.3/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o=