kafka

package
v0.1.40 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultBrokerAddr   = "localhost:9092" // The default broker address to use if no broker addresses are specified.
	DefaultBufferSize   = 1024
	DefaultNumProducers = 1
	DefaultNumWorkers   = 2
)

The default option values.

Variables

This section is empty.

Functions

This section is empty.

Types

type Log

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

Log is a logger that sends log messages to Kafka.

func New

func New(options ...Option) (*Log, error)

New returns a Kafka logger. It is the caller's responsibility to call Close on the returned *Log when finished with it, otherwise resources will leak.

func (*Log) Close

func (l *Log) Close() error

Close closes the logger.

func (*Log) LogMessage

func (l *Log) LogMessage(ctx context.Context, m logger.Message) error

LogMessage submits the given log message to Kafka.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option sets options on a Kafka logger.

func AddBrokerAddr

func AddBrokerAddr(addr ...string) Option

AddBrokerAddr adds the given addresses to the slice of Kafka broker address. Broker addresses should be in the format "hostname:port". DefaultBrokerAddr if and only if no broker addresses are added.

func BufferSize

func BufferSize(size int) Option

BufferSize sets the size of the message buffer.

func DebugLog

func DebugLog(l log.Interface) Option

DebugLog sets the logger to use for debugging information.

func Formatter

func Formatter(f logger.Formatter) Option

Formatter sets the formatter to use when converting log messages to strings.

func NumProducers

func NumProducers(n int) Option

NumProducers sets the number of Kafka producers to create.

func NumWorkers

func NumWorkers(n int) Option

NumWorkers sets the number of workers to create. The workers are responsible for feeding log messages to the Kafka producers. A good rule of thumb is to create twice as many workers as producers.

Jump to

Keyboard shortcuts

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