graylog

package module
v0.0.0-...-5859788 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2022 License: MIT Imports: 9 Imported by: 0

README

go-graylog

GoDoc

Graylog GELF messages sending using UDP, TCP or TCP/TLS, written in Golang.

Examples

package main

import (
	"time"

	"github.com/Devatoria/go-graylog"
)

func main() {
    // Initialize a new graylog client with TLS
	g, err := graylog.NewGraylogTLS(graylog.Endpoint{
		Transport: graylog.TCP,
		Address:   "localhost",
		Port:      12202,
	}, 3*time.Second, nil)
	if err != nil {
		panic(err)
	}

    // Send a message
	err = g.Send(graylog.Message{
		Version:      "1.1",
		Host:         "localhost",
		ShortMessage: "Sample test",
		FullMessage:  "Stacktrace",
		Timestamp:    time.Now().Unix(),
		Level:        1,
		Extra: map[string]string{
			"MY-EXTRA-FIELD": "extra_value",
		},
	})
    if err != nil {
        panic(err)
    }

    // Close the graylog connection
    if err := g.Close(); err != nil {
        panic(err)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeTimestamp

func MakeTimestamp() float64

Types

type Endpoint

type Endpoint struct {
	Transport Transport
	Address   string
	Port      uint
}

Endpoint represents a graylog endpoint

type GELF

type GELF struct {
	Graylog *Graylog
	Source  string
	Logger  string
}

GELF wrapper for Graylog instance

var Logger *GELF

Logger instance for GELF

func CreateLogger

func CreateLogger(settings GELFConfig) *GELF

CreateLogger - create instance of GELF

func (*GELF) Log

func (l *GELF) Log(shortMessage string, message string, severity uint)

Log generic log to Graylog function

func (*GELF) LogCritical

func (l *GELF) LogCritical(shortMessage string, message string)

LogCritical to provide .NET ILogger style function

func (*GELF) LogDebug

func (l *GELF) LogDebug(shortMessage string, message string)

LogDebug to provide .NET ILogger style function

func (*GELF) LogError

func (l *GELF) LogError(shortMessage string, message string)

LogError to provide .NET ILogger style function

func (*GELF) LogFatal

func (l *GELF) LogFatal(shortMessage string, message string)

LogFatal to provide .NET ILogger style function

func (*GELF) LogInformation

func (l *GELF) LogInformation(shortMessage string, message string)

LogInformation to provide .NET ILogger style function

func (*GELF) LogTrace

func (l *GELF) LogTrace(shortMessage string, message string)

LogTrace to provide .NET ILogger style function

func (*GELF) LogWarning

func (l *GELF) LogWarning(shortMessage string, message string)

LogWarning to provide .NET ILogger style function

type GELFConfig

type GELFConfig struct {
	GraylogServer string
	GraylogPort   uint
	GraylogSource string
}

GELFConfig definitions for Graylog host details

type Graylog

type Graylog struct {
	Client    *net.Conn
	TLSClient *tls.Conn
}

Graylog represents an established graylog connection

func NewGraylog

func NewGraylog(e Endpoint) (*Graylog, error)

NewGraylog instanciates a new graylog connection using the given endpoint

func NewGraylogTLS

func NewGraylogTLS(e Endpoint, timeout time.Duration, config *tls.Config) (*Graylog, error)

NewGraylogTLS instanciates a new graylog connection with TLS, using the given endpoint

func (*Graylog) Close

func (g *Graylog) Close() error

Close closes the opened connections of the given client

func (*Graylog) Send

func (g *Graylog) Send(m Message) error

Send writes the given message to the given graylog client

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    float64           `json:"timestamp,omitempty"`
	Level        uint              `json:"level,omitempty"`
	Extra        map[string]string `json:"-"`
}

Message represents a GELF formated message

type Transport

type Transport string

Transport represents a transport type enum

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