cloudflare/pint

Public

mirrored from https://github.com/cloudflare/pintAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.41.1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

cmd/pint/logger.go

40lines · modecode

1package main
2
3import (
4 "fmt"
5 "os"
6
7 "github.com/rs/zerolog"
8 "github.com/rs/zerolog/log"
9)
10
11func msgFormatter(msg interface{}) string {
12 return fmt.Sprintf("msg=%q", msg)
13}
14
15func lvlFormatter(level interface{}) string {
16 if level == nil {
17 return ""
18 }
19 return fmt.Sprintf("level=%s", level)
20}
21
22func initLogger(level string, noColor bool) error {
23 log.Logger = log.Logger.Output(zerolog.ConsoleWriter{
24 Out: os.Stderr,
25 NoColor: noColor,
26 FormatLevel: lvlFormatter,
27 FormatMessage: msgFormatter,
28 FormatTimestamp: func(interface{}) string {
29 return ""
30 },
31 })
32
33 l, err := zerolog.ParseLevel(level)
34 if err != nil {
35 return fmt.Errorf("'%s' is not a valid log level", level)
36 }
37 zerolog.SetGlobalLevel(l)
38
39 return nil
40}
41