cloudflare/pint
Publicmirrored from https://github.com/cloudflare/pintAvailable
cmd/pint/logger.go
30lines · modecode
| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "os" |
| 6 | |
| 7 | "github.com/fatih/color" |
| 8 | |
| 9 | "github.com/cloudflare/pint/internal/log" |
| 10 | ) |
| 11 | |
| 12 | func initLogger(level string, noColor bool) error { |
| 13 | l, err := log.ParseLevel(level) |
| 14 | if err != nil { |
| 15 | return fmt.Errorf("'%s' is not a valid log level", level) |
| 16 | } |
| 17 | |
| 18 | nc := os.Getenv("NO_COLOR") |
| 19 | if nc != "" && nc != "0" { |
| 20 | noColor = true |
| 21 | } |
| 22 | // Override fatih/color detection of when to **disable** coloring. |
| 23 | if !noColor { |
| 24 | color.NoColor = false |
| 25 | } |
| 26 | |
| 27 | log.Setup(l, noColor) |
| 28 | |
| 29 | return nil |
| 30 | } |
| 31 | |