buffer

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2020 License: MIT Imports: 5 Imported by: 2

README

Buffer

Generic buffer for batching entries, such as log entries.


GoDoc

Sponsors

This project is sponsored by CTO.ai, making it easy for development teams to create and share workflow automations without leaving the command line.

And my GitHub sponsors:

Documentation

Overview

Package buffer provides a generic buffer or batching mechanism for flushing entries at a given size or interval, useful for cases such as batching log events.

Index

Constants

This section is empty.

Variables

View Source
var DefaultFlushInterval = time.Second * 30

DefaultFlushInterval is the default flush interval.

View Source
var DefaultFlushTimeout = time.Second * 15

DefaultFlushTimeout is the default flush timeout.

View Source
var DefaultMaxEntries = 250

DefaultMaxEntries is the default max entries limit.

View Source
var DefaultMaxRetries = 3

DefaultMaxRetries is the default max retries limit.

Functions

This section is empty.

Types

type Buffer

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

Buffer is used to batch entries.

func New

func New(options ...Option) *Buffer

New buffer with the given options.

func (*Buffer) Close

func (b *Buffer) Close()

Close flushes any pending entries, and waits for flushing to complete. This method should be called before exiting your program to ensure entries have flushed properly.

func (*Buffer) Flush

func (b *Buffer) Flush()

Flush flushes any pending entries asynchronously.

func (*Buffer) FlushSync added in v1.1.0

func (b *Buffer) FlushSync()

FlushSync flushes any pending entries synchronously.

func (*Buffer) Push

func (b *Buffer) Push(value interface{})

Push adds a value to the buffer.

type ErrorFunc

type ErrorFunc func(error)

ErrorFunc is the error callback function used to report flushing errors, called when flushing fails and MaxRetries has exceeded on temporary errors.

type FlushFunc

type FlushFunc func(context.Context, []interface{}) error

FlushFunc is the flush callback function used to flush entries.

type Option

type Option func(*Buffer)

Option function.

func WithErrorHandler

func WithErrorHandler(fn ErrorFunc) Option

WithErrorHandler sets the function handling errors.

func WithFlushHandler

func WithFlushHandler(fn FlushFunc) Option

WithFlushHandler sets the function handling flushes.

func WithFlushInterval added in v1.0.1

func WithFlushInterval(d time.Duration) Option

WithFlushInterval sets the interval at which events are periodically flushed.

func WithFlushTimeout added in v1.0.1

func WithFlushTimeout(d time.Duration) Option

WithFlushTimeout sets the flush timeout.

func WithMaxEntries added in v1.0.1

func WithMaxEntries(n int) Option

WithMaxEntries sets the maximum number of entries before flushing.

func WithMaxRetries added in v1.0.1

func WithMaxRetries(n int) Option

WithMaxRetries sets the maximum number of retries for temporary flush errors.

Jump to

Keyboard shortcuts

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