logger color for windows cmd(#2383)

enable logger color for windows cmd/powershell.
This commit is contained in:
Ruony 2020-06-09 16:17:25 +02:00
parent 5e40c1d49c
commit 3164291586
3 changed files with 9 additions and 0 deletions

1
go.mod
View File

@ -8,6 +8,7 @@ require (
github.com/golang/protobuf v1.3.3 github.com/golang/protobuf v1.3.3
github.com/json-iterator/go v1.1.9 github.com/json-iterator/go v1.1.9
github.com/mattn/go-isatty v0.0.12 github.com/mattn/go-isatty v0.0.12
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644
github.com/stretchr/testify v1.4.0 github.com/stretchr/testify v1.4.0
github.com/ugorji/go/codec v1.1.7 github.com/ugorji/go/codec v1.1.7
gopkg.in/yaml.v2 v2.2.8 gopkg.in/yaml.v2 v2.2.8

2
go.sum
View File

@ -26,6 +26,8 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLD
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 h1:X+yvsM2yrEktyI+b2qND5gpH8YhURn0k8OCaeRnkINo=
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644/go.mod h1:nkxAfR/5quYxwPZhyDxgasBMnRtBZd0FCEpawpjMUFg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=

View File

@ -9,9 +9,11 @@ import (
"io" "io"
"net/http" "net/http"
"os" "os"
"runtime"
"time" "time"
"github.com/mattn/go-isatty" "github.com/mattn/go-isatty"
"github.com/shiena/ansicolor"
) )
type consoleColorModeValue int type consoleColorModeValue int
@ -221,6 +223,10 @@ func LoggerWithConfig(conf LoggerConfig) HandlerFunc {
isTerm = false isTerm = false
} }
if runtime.GOOS == "windows" {
out = ansicolor.NewAnsiColorWriter(out)
}
var skip map[string]struct{} var skip map[string]struct{}
if length := len(notlogged); length > 0 { if length := len(notlogged); length > 0 {