cloudflare/pint
Publicmirrored from https://github.com/cloudflare/pintAvailable
cmd/pint/logger.go
39lines · modecode
| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "os" |
| 6 | |
| 7 | "github.com/rs/zerolog" |
| 8 | "github.com/rs/zerolog/log" |
| 9 | ) |
| 10 | |
| 11 | func msgFormatter(msg interface{}) string { |
| 12 | return fmt.Sprintf("msg=%q", msg) |
| 13 | } |
| 14 | func lvlFormatter(level interface{}) string { |
| 15 | if level == nil { |
| 16 | return "" |
| 17 | } |
| 18 | return fmt.Sprintf("level=%s", level) |
| 19 | } |
| 20 | |
| 21 | func initLogger(level string) error { |
| 22 | log.Logger = log.Logger.Output(zerolog.ConsoleWriter{ |
| 23 | Out: os.Stderr, |
| 24 | NoColor: false, |
| 25 | FormatLevel: lvlFormatter, |
| 26 | FormatMessage: msgFormatter, |
| 27 | FormatTimestamp: func(interface{}) string { |
| 28 | return "" |
| 29 | }, |
| 30 | }) |
| 31 | |
| 32 | l, err := zerolog.ParseLevel(level) |
| 33 | if err != nil { |
| 34 | return err |
| 35 | } |
| 36 | zerolog.SetGlobalLevel(l) |
| 37 | |
| 38 | return nil |
| 39 | } |
| 40 | |