Documentation
¶
Overview ¶
Package buffer provides a pool-allocated byte buffer with custom methods.
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"}), ) // register as default slog.SetDefault(log.Logger) }
Output:
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.
Functions ¶
func SetFacility ¶ added in v0.4.0
func SetFacility(s string)
SetFacility set Facility log filed used when generating a log message in GELF format. By default, it is filled in during initialization using the path to the main module of the application.
If you want to change this value, then this must be done before initializing the log.
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.