zlogrus

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: MIT Imports: 5 Imported by: 0

README

ZincSearch Hook for Logrus

The inspiration comes from elogrus

version support

Test with ZincSearch v0.4.9

Usage

package main

import (
	"context"
	"github.com/PearceDuan/zlogrus"
	"github.com/sirupsen/logrus"
	client "github.com/zinclabs/sdk-go-zincsearch"
	"time"
)

func main() {
	log := logrus.New()

	configuration := client.NewConfiguration()
	configuration.Servers[0].URL = "http://127.0.0.1:4080"
	apiClient := client.NewAPIClient(configuration)
	authCtx := context.WithValue(context.Background(), client.ContextBasicAuth, client.BasicAuth{
		UserName: "your-zincsearch-username",
		Password: "your-zincsearch-password",
	})
	hook, err := zlogrus.NewAsyncZincHook(authCtx, apiClient, "localhost", logrus.DebugLevel, "test_log")
	if err != nil {
		log.Panic(err)
	}
	log.Hooks.Add(hook)

	log.WithFields(logrus.Fields{
		"name": "joe",
		"age":  42,
	}).Error("Hello world!")
	time.Sleep(5 * time.Second)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IndexNameFunc

type IndexNameFunc func() string

IndexNameFunc get index name

type ZincHook

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

ZincHook is a logrus hook for ZincSearch

func NewAsyncZincHook

func NewAsyncZincHook(ctx context.Context, client *client.APIClient, host string, level logrus.Level, index string) (*ZincHook, error)

NewAsyncZincHook creates new hook with asynchronous log. client - ZincSearch client with specific es version (v5/v6/v7/...) host - host of system level - log level index - name of the index in ZincSearch

func NewAsyncZincHookWithFunc

func NewAsyncZincHookWithFunc(ctx context.Context, client *client.APIClient, host string, level logrus.Level, indexFunc IndexNameFunc) (*ZincHook, error)

NewAsyncZincHookWithFunc creates new asynchronous hook with function that provides the index name. This is useful if the index name is somehow dynamic especially based on time. client - ZincSearch client with specific es version (v5/v6/v7/...) host - host of system level - log level indexFunc - function providing the name of index

func NewZincHook

func NewZincHook(ctx context.Context, client *client.APIClient, host string, level logrus.Level, index string) (*ZincHook, error)

NewZincHook creates new hook. client - ZincSearch client host - host of system level - log level index - name of the index in ZincSearch

func NewZincHookWithFunc

func NewZincHookWithFunc(ctx context.Context, client *client.APIClient, host string, level logrus.Level, indexFunc IndexNameFunc) (*ZincHook, error)

NewZincHookWithFunc creates new hook with function that provides the index name. This is useful if the index name is somehow dynamic especially based on time. client - ZincSearch client with specific es version (v5/v6/v7/...) host - host of system level - log level indexFunc - function providing the name of index

func (*ZincHook) Cancel

func (hook *ZincHook) Cancel()

Cancel all calls to elastic

func (*ZincHook) Fire

func (hook *ZincHook) Fire(entry *logrus.Entry) error

Fire is required to implement Logrus hook

func (*ZincHook) Levels

func (hook *ZincHook) Levels() []logrus.Level

Levels Required for logrus hook implementation

Jump to

Keyboard shortcuts

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