Package graylog provides support for logging to the Graylog server.
It can send messages to the Graylog server using UDP or TCP. When using UDP as a transport layer, the messages sent are gzip compressed and automatically chunked.
import (
"time""github.com/mdigger/graylog""golang.org/x/exp/slog"
)
funcmain() {
// init graylog loggerlog, err:=graylog.Dial("udp", "localhost:12201")
iferr!=nil {
panic(err)
}
deferlog.Close()
// send debug message with attributeslog.Debug("Test message.\nMore info...",
slog.Any("log", log),
slog.Bool("bool", true),
slog.Time("now", time.Now()),
slog.Group("group",
slog.String("str", "string value"),
slog.Duration("duration", time.Hour/3)),
slog.Any("object", struct {
Textstring`json:"text"`
}{Text: "text"}),
)
// register as defaultslog.SetDefault(log.Logger)
}