eslogger

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2021 License: MIT Imports: 12 Imported by: 1

README

eslogger

package eslogger implements kit log interface write log message into elasticsearch datastream

usage

create a logger with streamName logs-test-log.

streamName should match one of index templates index patterns for detail

//create config
conf := eslogger.NewConfig("http://127.0.0.1:9200", "logs-test-log")

//set sync duration
conf.Tick(time.Second)

//create logger
logger := eslogger.New(conf)

//start working loop
if err := logger.Open(context.Background()); err != nil {
    panic(err)
}


logger.Log("message", "Test message", "val", 23)

//stop running loop
logger.Close()

Documentation

Index

Constants

View Source
const (
	DefaultMaxSize  = 4096
	DefaultDuration = time.Millisecond * 100
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ESLogger

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

ESLogger encode keyvals into json object. and store in a internal buf. the buf content will be synced to elastich search datastream in tick period or if buf size exceed bufMaxSize

func New

func New(eslc *ESLoggerConfig) *ESLogger

New create a new ESLogger instrance with eslc config

func (*ESLogger) Close

func (esds *ESLogger) Close() error

Close stop running goroutine

func (*ESLogger) Log

func (esds *ESLogger) Log(keyvals ...interface{}) error

Log send data to working goroutine. the @timestamp field will append automatically

func (*ESLogger) Open

func (esds *ESLogger) Open() error

Open start working goroutine encode log data into json object and sync to elasticsearch datastream with bulk request

type ESLoggerConfig

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

ESLoggerConfig define the config property which used to create ESlogger instance

func NewConfig

func NewConfig(address string, streamName string) *ESLoggerConfig

NewConfig return a new ESLoggerConfig with sepcifc address(scheme://ip:port) and streamName

func (*ESLoggerConfig) BasicAuth

func (eslc *ESLoggerConfig) BasicAuth(user, pass string) *ESLoggerConfig

BasicAuth set user, password which used to basic authentication

func (*ESLoggerConfig) BufMaxSize

func (eslc *ESLoggerConfig) BufMaxSize(maxSize int) *ESLoggerConfig

BufMaxSize sepcific internal buf maxSize instread of DefaultMaxSize

func (*ESLoggerConfig) DisableTimestamp

func (eslc *ESLoggerConfig) DisableTimestamp()

DisabledTimeatmp disable automatically add the '@timestamp' field

func (*ESLoggerConfig) Loggger

func (eslc *ESLoggerConfig) Loggger(logger *log.Logger) *ESLoggerConfig

Logger spcific logger instance which used to write error log during sync process

func (*ESLoggerConfig) Tick

func (eslc *ESLoggerConfig) Tick(d time.Duration) *ESLoggerConfig

Tick specific sync duration instead of DefaultDuration

func (*ESLoggerConfig) Transport

func (eslc *ESLoggerConfig) Transport(rp http.RoundTripper) *ESLoggerConfig

Transport sepcific transport instance which used to build elastic client if not specific the default http.Transport will be used

Jump to

Keyboard shortcuts

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