Skip to content

Commit

Permalink
Merge pull request #642 from Fenny/master
Browse files Browse the repository at this point in the history
🎨 Fix colors for Windows
  • Loading branch information
Fenny committed Jul 19, 2020
2 parents 9054d02 + 2e4205d commit 5005561
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
13 changes: 9 additions & 4 deletions middleware/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5005561

Please sign in to comment.