graylog

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2022 License: MIT Imports: 6 Imported by: 0

README

godoc license CodeFactor

Go Graylog package

This package implement Graylog GELF interface to send message using UDP or TCP transport, in Golang.

Example

package main

import (
	"github.com/thomasdseao/go-graylog"
)

func main() {
	// Create Gelf instance
	gelf := graylog.NewGelf(graylog.Config{
		"graylog1.example.com",
		2202,
		graylog.UDP,
		true,
	})
    
	// Create message and JSON encode it
	message := graylog.Message{
		Version:      "1.1",
		Host:         "example.com",
		ShortMessage: "This is the short message",
	}
	jsonMessage, _ := json.Marshal(message)
	
	// Send message
	sent, err := gelf.Send(jsonMessage)

}

Tests

go test

Contribute

Feel free to submit PR with another implementations of Graylog or improvements.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Hostname  string
	Port      int
	Transport Transport
	ErrorLog  bool
}

type Gelf

type Gelf struct {
	Config Config
}

func NewGelf

func NewGelf(config Config) *Gelf

func (*Gelf) Send

func (gelf *Gelf) Send(message []byte) (bool, error)

type Message

type Message struct {
	Version      string                 `json:"version"`
	Host         string                 `json:"host"`
	ShortMessage string                 `json:"short_message"`
	FullMessage  string                 `json:"full_message,omitempty"`
	Timestamp    int64                  `json:"timestamp,omitempty"`
	Level        uint                   `json:"level,omitempty"`
	Extra        map[string]interface{} `json:"-,"`
}

type Transport

type Transport string
const (
	UDP Transport = "udp"
	TCP Transport = "tcp"
)

Jump to

Keyboard shortcuts

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