zerolog_logstash

package module
v1.0.3 Latest Latest
Warning

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

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

README

Zerolog Logstash writer

This writer communicates with default logstash beats input. As zerolog default writes the output in json the logstash input uses json codec.

Logstash go client

This zerolog logstash writer uses go-lumber client. For more info visit go-lumber repository. As the client is non blocking, it uses buffer channel where each write processes the input and stores the result into buffer. The asynchronous worker then processes the buffer when is full or when Flush is called, e.g:

lw.Flush(1*time.Second)

When the Flush is not called, the last bufferSize messages are definitelly lost. When the program wants to avoid using flushing, pass the context of the main function into worker so it flushes the stream at the end of program.

Tests

Tests are written with locally hosted logstash service. To run tests there have to be spawned logstash service before running tests locally. Simply run docker compose and tests

docker compose up -d
go test ./...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*options)

Option function

func WithAddress

func WithAddress(value string) Option

IP Address with port of running instance.

func WithBufferSize

func WithBufferSize(value int) Option

Buffer size that specifies how big batches are processed written to logstash service at once. Minimum is 1

func WithContext

func WithContext(ctx context.Context) Option

WithContext should be used when context will expire/ be canceled so the rest of the buffer is sent to logstash Alternativelly use Flush(time.Duration) function

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Logstash writer using lumber Client which is default input filter in logstash service

func NewWriter

func NewWriter(client *lumber.Client, opts ...Option) *Writer

func (*Writer) Flush

func (lw *Writer) Flush(timeout time.Duration) bool

Flush rest of the items

func (*Writer) Write

func (lw *Writer) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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