Documentation ¶
Overview ¶
Package zaplogfmt provides a zap encoder that formats log entries in "logfmt" format.
Example (Array) ¶
package main import ( "os" zaplogfmt "github.com/sykesm/zap-logfmt" "go.uber.org/zap" "go.uber.org/zap/zapcore" ) func main() { config := zap.NewProductionEncoderConfig() config.TimeKey = "" logger := zap.New(zapcore.NewCore( zaplogfmt.NewEncoder(config), os.Stdout, zapcore.DebugLevel, )) logger.Info("counting", zap.Ints("values", []int{0, 1, 2, 3})) }
Output: level=info msg=counting values=[0,1,2,3]
Example (Object) ¶
package main import ( "os" zaplogfmt "github.com/sykesm/zap-logfmt" "go.uber.org/zap" "go.uber.org/zap/zapcore" ) type Person struct { First string Last string Age int } func (p Person) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("first", p.First) enc.AddString("last", p.Last) enc.AddInt("age", p.Age) return nil } func main() { config := zap.NewProductionEncoderConfig() config.TimeKey = "" logger := zap.New(zapcore.NewCore( zaplogfmt.NewEncoder(config), os.Stdout, zapcore.DebugLevel, )) person := Person{First: "Arthur", Last: "Dent", Age: 42} logger.Warn("hitchhiker discovered", zap.Object("identity", person)) }
Output: level=warn msg="hitchhiker discovered" identity="first=Arthur last=Dent age=42"
Example (Usage) ¶
package main import ( "os" zaplogfmt "github.com/sykesm/zap-logfmt" "go.uber.org/zap" "go.uber.org/zap/zapcore" ) func main() { config := zap.NewProductionEncoderConfig() config.TimeKey = "" logger := zap.New(zapcore.NewCore( zaplogfmt.NewEncoder(config), os.Stdout, zapcore.DebugLevel, )).Named("main").With(zap.String("type", "greeting")) logger.Info("Hello World") }
Output: level=info logger=main msg="Hello World" type=greeting
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewEncoder ¶
func NewEncoder(cfg zapcore.EncoderConfig) zapcore.Encoder
NewEncoder creates an encoder writes logfmt formatted log entries.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.