fastgelf

package module
v0.0.0-...-8f2ec72 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2019 License: MIT Imports: 6 Imported by: 0

README

FastGELF is an experimental GELF library

This is a Go library for writing log messages in the GELF format to a remote endpoint.

What this library doesn't do:

  • No chunking support.
  • No compression support.
  • No TCP support.
  • No support for listening and reading messages.

If you are looking for a feature complete GELF library try https://github.com/Graylog2/go-gelf.

What it does

This library is optimized for writing a large number of UDP GELF messages on Linux.

It uses the sendmmsg syscall, which is only available on Linux, to reduce the number of times we cross kernel boundaries when sending a huge amount of log messages.

This library will still work on non-linux environments (tested on Darwin) but the performance improvement won't be so noticeable.

Benchmarks

These benchmarks compare this library to the Graylog2/go-gelf library.

Linux:

$ go test -test.bench . -test.benchmem -test.benchtime 3s
goos: linux
goarch: amd64
pkg: github.com/cezarsa/fastgelf/experiments
Benchmark_FastGELF_WriteMessageExtra/simple         	  500000	      7633 ns/op	     203 B/op	       4 allocs/op
Benchmark_FastGELF_WriteMessageExtra/with_extra     	 1000000	      7535 ns/op	     200 B/op	       4 allocs/op
Benchmark_gogelf_WriteMessageExtra/simple           	  500000	     10941 ns/op	     176 B/op	       1 allocs/op
Benchmark_gogelf_WriteMessageExtra/with_extra       	  300000	     17108 ns/op	     752 B/op	      14 allocs/op
PASS

Darwin:

$ go test -test.bench . -test.benchmem -test.benchtime 3s
goos: darwin
goarch: amd64
pkg: github.com/cezarsa/fastgelf/experiments
Benchmark_FastGELF_WriteMessageExtra/simple-4         	  300000	     13937 ns/op	     241 B/op	       8 allocs/op
Benchmark_FastGELF_WriteMessageExtra/with_extra-4     	  300000	     13383 ns/op	     242 B/op	       8 allocs/op
Benchmark_gogelf_WriteMessageExtra/simple-4           	  500000	     14276 ns/op	     176 B/op	       1 allocs/op
Benchmark_gogelf_WriteMessageExtra/with_extra-4       	  300000	     15290 ns/op	     752 B/op	      14 allocs/op
PASS

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Logger = log.New(os.Stderr, "", log.LstdFlags)

Functions

This section is empty.

Types

type Message

type Message struct {
	Version  string
	Host     string
	Short    string
	Full     string
	TimeUnix float64
	Level    int32
	Facility string
	Extra    map[string]interface{}
	RawExtra []byte
}

func (*Message) IsNil

func (m *Message) IsNil() bool

func (*Message) MarshalJSONObject

func (m *Message) MarshalJSONObject(enc *gojay.Encoder)

type UDPWriter

type UDPWriter struct {
	FlushInterval time.Duration
	// contains filtered or unexported fields
}

func NewUDPWriter

func NewUDPWriter(addr string) (*UDPWriter, error)

func (*UDPWriter) Close

func (w *UDPWriter) Close() error

func (*UDPWriter) WriteMessage

func (w *UDPWriter) WriteMessage(msg *Message) error

Jump to

Keyboard shortcuts

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