Merge pull request #642 from Fenny/master

🎨 Fix colors for Windows
pull/643/head v1.13.1
fenny 2020-07-19 13:20:52 +02:00 committed by GitHub
commit 500556178a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 5 deletions

2
app.go
View File

@ -33,7 +33,7 @@ import (
)
// Version of current package
const Version = "1.13.0"
const Version = "1.13.1"
// Map is a shortcut for map[string]interface{}, useful for JSON returns
type Map map[string]interface{}

View File

@ -13,7 +13,8 @@ import (
fiber "github.com/gofiber/fiber"
utils "github.com/gofiber/utils"
"github.com/mattn/go-isatty"
colorable "github.com/mattn/go-colorable"
isatty "github.com/mattn/go-isatty"
bytebufferpool "github.com/valyala/bytebufferpool"
)
@ -187,11 +188,15 @@ func logger(config LoggerConfig) fiber.Handler {
config.TimeFormat = LoggerConfigDefault.TimeFormat
}
if config.Output == nil {
// Check if colors are supported if no Output is given
if os.Getenv("TERM") != "dumb" && (isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd())) {
// Check if colors should be disabled
if os.Getenv("TERM") == "dumb" ||
(!isatty.IsTerminal(os.Stdout.Fd()) && !isatty.IsCygwinTerminal(os.Stdout.Fd())) {
config.Output = LoggerConfigDefault.Output
} else {
config.enableColors = true
config.Output = colorable.NewColorableStderr()
}
config.Output = LoggerConfigDefault.Output
}
// Middleware settings
var mutex sync.RWMutex