MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / NewZap

Function NewZap

pkg/log/zap_handler.go:27–52  ·  view source on GitHub ↗

NewZap returns a new log handler based on the zap library.

(encoding string)

Source from the content-addressed store, hash-verified

25
26// NewZap returns a new log handler based on the zap library.
27func NewZap(encoding string) (Handler, error) {
28 config := zap.Config{
29 Level: zap.NewAtomicLevelAt(zap.DebugLevel), // levels are currently still filtered by the Logger.
30 Encoding: encoding,
31 EncoderConfig: zap.NewProductionEncoderConfig(),
32 OutputPaths: []string{"stderr"},
33 ErrorOutputPaths: []string{"stderr"},
34 }
35 config.DisableCaller = true // omit caller from log message.
36 config.EncoderConfig.TimeKey = "" // omit timestamp from log message.
37 if encoding == "console" {
38 config.EncoderConfig.EncodeLevel = zapcore.CapitalLevelEncoder
39 colorterm, _ := strconv.ParseBool(os.Getenv("COLORTERM"))
40 if !colorterm && os.Getenv("COLORTERM") == "truecolor" {
41 colorterm = true
42 }
43 if colorterm {
44 config.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
45 }
46 }
47 logger, err := config.Build()
48 if err != nil {
49 return nil, err
50 }
51 return &zapHandler{Logger: logger}, nil
52}
53
54type zapHandler struct {
55 *zap.Logger

Callers 4

logWarningsFunction · 0.92
GetLoggerFunction · 0.92
initFunction · 0.92
InitializeLoggerFunction · 0.92

Calls 1

BuildMethod · 0.45

Tested by 1

initFunction · 0.74