This library provides in-process aggregated collector of messages and web page to report them. They are useful for last mile observability of logs.
logz
is inspired by OpenCensus zPages.
- High performance and low resource consumption.
- Adapter for
go.uber.org/zap
. - Adapter for
github.com/bool64/ctxd
. - HTTP handler to serve aggregated messages.
- Best effort filtering of dynamic parts of messages.
zc := zap.NewDevelopmentConfig()
zz, lo := zzap.NewOption(logz.Config{
MaxCardinality: 5,
MaxSamples: 10,
FilterMessage: true,
})
l, err := zc.Build(zz)
if err != nil {
panic(err)
}
l.Debug("starting example")
l.Sugar().Infow("sample info", "one", 1, "two", 2)
l.Error("unexpected end of the world")
l.Warn("please be careful with asf872dfse732")
l.Warn("please be careful with sdf890sdf0w9d") // These messages will be grouped together with help of filtering.
l.Info("starting server at http://localhost:6060/")
err = http.ListenAndServe("0.0.0.0:6060", logzpage.Handler(lo...))
if err != nil {
l.Fatal(err.Error())
}
var logger ctxd.Logger
lz := ctxz.NewObserver(logger, logz.Config{
MaxCardinality: 100,
MaxSamples: 50,
DistRetentionPeriod: 72 * time.Hour,
})
logger = lz
ctx := context.TODO()
logger.Debug(ctx, "starting example")
logger.Info(ctx, "sample info", "one", 1, "two", 2)
logger.Error(ctx, "unexpected end of the world")
logger.Important(ctx, "starting server at http://localhost:6060/")
err := http.ListenAndServe("0.0.0.0:6060", logzpage.Handler(lz.LevelObservers()...))
if err != nil {
logger.Error(ctx, err.Error())
os.Exit(1)
}