eslogger

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2020 License: MIT Imports: 8 Imported by: 0

README

ElasticSearch Logger

This is a golang package that sends logs to an ElasticSearch instance through a custom zerolog transport.

Basic Usage (with zerolog integration)
package main

import (
	"github.com/joshuasprow/eslogger"
	"github.com/rs/zerolog/log"
)

func main() {
	conf := eslogger.Config{
		Index: "test-index", // Will be appended with "-year-month-date"
		Addresses: []string{
			"http://localhost:9200",
			"http://localhost:9201",
		},
		Username: "me",
		Password: "supersecretpassword",
		Headers: map[string]string{
			"Auth-Client-Id":     "stringofnastycharacters",
			"Auth-Client-Secret": "stringofnastycharacters",
		},
	}

	logger, err := eslogger.New(conf)
	if err != nil {
		log.Fatal().Err(err).Msg("failed to initialize logger")
	}

	log.Logger = logger

	log.Info().Msg("I'm logging to ElasticSearch!")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(conf Config) (logger zerolog.Logger, err error)

New returns a zerolog.Logger, which transports to an elasticsearch instance using the passed-in config struct.

Types

type Config

type Config struct {
	Addresses []string
	Headers   map[string]string
	Index     string
	Password  string
	Username  string
}

Config includes the elasticsearch connection information and index name

Jump to

Keyboard shortcuts

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