xes

package module
v0.0.0-...-23fc08c Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2023 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	// DebugLevel defines debug log level.
	DebugLevel = iota
	// InfoLevel defines info log level.
	InfoLevel
	// WarnLevel defines warn log level.
	WarnLevel
	// ErrorLevel defines error log level.
	ErrorLevel
	// FatalLevel defines fatal log level.
	FatalLevel
	// PanicLevel defines panic log level.
	PanicLevel
	// NoLevel defines an absent log level.
	NoLevel
	// Disabled disables the logger.
	Disabled

	// TraceLevel defines trace log level.
	TraceLevel = -1
)
View Source
const (
	ReceiverEs int = iota + 1
	ReceiverStdout
	ReceiverPp
	ReceiverDump
)

Variables

View Source
var (
	ErrIndexRequired   = errors.New("index name is required")
	ErrServersRequired = errors.New("server urls required")
	ErrServerIsEmpty   = errors.New("server url is empty")
)

Functions

func LevelString

func LevelString(level int) string

Types

type EsLogger

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

EsLogger an elastic writer can be used for zerolog

func NewEsLogger

func NewEsLogger(esOpts ...EsOption) (*EsLogger, error)
Example
_, err := NewEsLogger()
fmt.Println(err == ErrServersRequired)
_, err = NewEsLogger(WithUrls(""))
fmt.Println(err == ErrServerIsEmpty)

urls := []string{"http://127.0.0.1:10000"}
_, err = NewEsLogger(WithUrls(urls...))
fmt.Println(err == ErrServerIsEmpty)
fmt.Println(err == ErrIndexRequired)

_, err = NewEsLogger(
	WithUrls(urls...),
	WithIndexName("test"),
	WithLevel(DebugLevel),
	WithUsername("xxx"),
	WithPassword("xxx"),
)
fmt.Println(err != nil)
Output:

true
true
false
false
true

func (*EsLogger) Write

func (l *EsLogger) Write(p []byte) (n int, err error)

Write implements io.Writer, so we can use EsLogger as io.Writer

type EsOption

type EsOption func(o *Option)

func WithIndexName

func WithIndexName(indexName string) EsOption

func WithLevel

func WithLevel(level int) EsOption

func WithPassword

func WithPassword(password string) EsOption

func WithReceiver

func WithReceiver(i int) EsOption

func WithUrls

func WithUrls(urls ...string) EsOption

func WithUsername

func WithUsername(username string) EsOption

type MyRetrier

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

MyRetrier this is copied from https://github.com/olivere/elastic/wiki/Retrier-and-Backoff

func (*MyRetrier) Retry

func (r *MyRetrier) Retry(ctx context.Context, retry int, req *http.Request, resp *http.Response, err error) (time.Duration, bool, error)

type Option

type Option struct {
	// the log Receiver: is not used by now
	Receiver int `json:"receiver" yaml:"receiver" redis:"receiver" structs:"receiver"`

	Disabled bool `json:"disabled" yaml:"disabled" redis:"disabled" structs:"disabled"`

	// log Level
	Level int `json:"level" yaml:"level" redis:"level" structs:"level"`

	// Retries
	Retries int `json:"retries" yaml:"retries" redis:"retries" structs:"retries"`

	// Timeout
	Timeout int `json:"timeout" yaml:"timeout" redis:"timeout" structs:"timeout"`

	// index name for es
	IndexName   string `json:"index_name" yaml:"index_name" redis:"index_name" structs:"index_name"`
	IndexSuffix string `json:"index_suffix" yaml:"index_suffix" redis:"index_suffix" structs:"index_suffix"`

	// Urls
	Urls []string `json:"urls" yaml:"urls" redis:"urls" structs:"urls"`

	// WithFuncName
	WithFuncName bool `json:"with_func_name" yaml:"with_func_name" redis:"with_func_name" structs:"with_func_name"`
	WithSysinfo  bool `json:"with_sysinfo" yaml:"with_sysinfo" redis:"with_sysinfo" structs:"with_sysinfo"`

	// basic auth
	Username string `json:"username" yaml:"username" redis:"username" structs:"username"`
	Password string `json:"password" yaml:"password" redis:"password" structs:"password"`
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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