Documentation
¶
Overview ¶
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.
Example ¶
package main
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 info message with attributes
log.Info("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("struct", struct {
Test string `json:"test"`
}{Test: "test"}),
)
}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrMessageToLarge = errors.New("message too large")
ErrMessageToLarge returns when trying to send too long message other UDP.
var Facility string
Used when generating a log message in GELF format. If you want to change this value, then this must be done before initializing the log.
Functions ¶
This section is empty.
Types ¶
type Logger ¶
Logger is an io.Logger for sending log messages to the Graylog server.
func Dial ¶
Dial establishes a connection to the Graylog server and returns Logger to send log messages.
Supported networks are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only), "udp", "udp4" (IPv4-only), "udp6" (IPv6-only). When using UDP as a transport layer, the messages sent are compressed using GZIP and automatically chunked.
Attrs specify a list of attributes that will be added to all messages sent to Graylog server.