An open API service indexing awesome lists of open source software.

https://github.com/mdigger/graylog

Support for logging to the Graylog server in golang (slog handler)
https://github.com/mdigger/graylog

go golang graylog slog slog-graylog slog-handler

Last synced: 4 months ago
JSON representation

Support for logging to the Graylog server in golang (slog handler)

Awesome Lists containing this project

README

          

# graylog logger

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.

```golang
import (
"time"
"github.com/mdigger/graylog"
"golang.org/x/exp/slog"
)

func main() {
// init graylog logger
log, err := graylog.Dial("udp", "localhost:12201")
if err != nil {
panic(err)
}
defer log.Close()

// send debug message with attributes
log.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 {
Text string `json:"text"`
}{Text: "text"}),
)

// register as default
slog.SetDefault(log.Logger)
}
```