gelf

package module
v0.0.0-...-68dd11b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2023 License: MIT Imports: 7 Imported by: 0

README

Go client for GELF protocol

Only UDP.

Example

package main

import (
	"fmt"
	"log"

	"github.com/Zandarn/gelf"
)

func main() {
	client := gelf.GelfClient()
	client.Config.Endpoint = "192.168.1.1:12201"

	gelfMessage := gelf.Message{
		Message:  "Example message",
		Level:    gelf.LogLevel.WARNING,
		Facility: gelf.LogFacility.LOCAL0,
		Extra: map[string]string{
			"Extra-key":   "extra_value",
			"Another key": "another value",
		},
	}

	length, err := client.SendMessage(gelfMessage)
	if err != nil {
		log.Printf("Error: %s", err)
	}

	fmt.Println(length)
}

Documentation

Index

Constants

View Source
const (
	EMERGENCY int = 0
	ALERT     int = 1
	CRITICAL  int = 2
	ERROR     int = 3
	WARNING   int = 4
	NOTICE    int = 5
	INFO      int = 6
	DEBUG     int = 7
)
View Source
const (
	LOCAL0 string = "local0"
	LOCAL1 string = "local1"
	LOCAL2 string = "local2"
	LOCAL3 string = "local3"
	LOCAL4 string = "local4"
	LOCAL5 string = "local5"
	LOCAL6 string = "local6"
	LOCAL7 string = "local7"
)

Variables

View Source
var LogFacility = facility{}
View Source
var LogLevel = level{}

Functions

This section is empty.

Types

type Client

type Client struct {
	Config *Config
}

func GelfClient

func GelfClient() *Client

func (*Client) SendMessage

func (g *Client) SendMessage(message Message) (n int, err error)

type Config

type Config struct {
	Endpoint     string
	MaxChunkSize int
}

type Message

type Message struct {
	Version   string            `json:"version"`
	Host      string            `json:"host"`
	Message   string            `json:"message"`
	Timestamp float64           `json:"timestamp"`
	Level     int               `json:"level"`
	Facility  string            `json:"facility"`
	Extra     map[string]string `json:"-"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL