From 3164291586a3c350744ea279f7627426a6ebfa3a Mon Sep 17 00:00:00 2001 From: Ruony Date: Tue, 9 Jun 2020 16:17:25 +0200 Subject: [PATCH] logger color for windows cmd(#2383) enable logger color for windows cmd/powershell. --- go.mod | 1 + go.sum | 2 ++ logger.go | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/go.mod b/go.mod index cfaee746..db4cffd5 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/golang/protobuf v1.3.3 github.com/json-iterator/go v1.1.9 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/ugorji/go/codec v1.1.7 gopkg.in/yaml.v2 v2.2.8 diff --git a/go.sum b/go.sum index 4c14fb83..878c179b 100644 --- a/go.sum +++ b/go.sum @@ -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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 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/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= diff --git a/logger.go b/logger.go index d361b74d..a2ee863d 100644 --- a/logger.go +++ b/logger.go @@ -9,9 +9,11 @@ import ( "io" "net/http" "os" + "runtime" "time" "github.com/mattn/go-isatty" + "github.com/shiena/ansicolor" ) type consoleColorModeValue int @@ -221,6 +223,10 @@ func LoggerWithConfig(conf LoggerConfig) HandlerFunc { isTerm = false } + if runtime.GOOS == "windows" { + out = ansicolor.NewAnsiColorWriter(out) + } + var skip map[string]struct{} if length := len(notlogged); length > 0 {