logruskit

package module
v0.0.0-...-cbb9e95 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2020 License: MIT Imports: 5 Imported by: 0

README

Deprecated: This package is deprecated in favor of zap and hexa stacked logger.

Logrus-kit is a kit for logrus.

Logrus-kit inspired by Logrus mate

Install
go get github.com/Kamva/logrus-kit
Formatter list:
  • json
  • text
Hook list:
  • slack
Output list
  • stdout
  • stderr
  • null
Example

Note: To register default logrus-kit formatters,hooks and outputs , import logrusbase : e.g
import _ "github.com/Kamva/logrus-kit/logrusbase"

Example:

package mypackage

import (
	"github.com/Kamva/logrus-kit"
	_ "github.com/Kamva/logrus-kit/logrusbase"
	"github.com/sirupsen/logrus"
	"github.com/spf13/viper"
)

func main() {
	v := viper.New()
	v.SetDefault("log.level", "info")
	v.SetDefault("log.formatter", "text")
	v.SetDefault("log.output", "stderr")
	v.SetDefault("log.hooks", "")

	logger := logrus.New()

	err := logruskit.Tune(logger, logruskit.NewViperAdapter(v))

	if err != nil {
		panic(err)
	}

	logger.WithFields(logrus.Fields{"test": "is ok"}).Info("salam")
}
Todo:
  • Add more formatter and logger.
  • Write tests.
  • CI.
  • Write example.
  • PR to logrus to add this to other logrus tools.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterFormatter

func RegisterFormatter(name string, fn FormatterFunc)

RegisterFormatter function register new formatter.

func RegisterHook

func RegisterHook(name string, fn HookFunc)

RegisterHook function register new hook.

func RegisterOutput

func RegisterOutput(name string, fn OutputFunc)

RegisterOutput register writer.

func Tune

func Tune(logger *logrus.Logger, config Config) error

Tune tune your logger with settings.

Types

type Config

type Config interface {
	Get(key string) interface{}
	GetString(key string) string
	GetInt64(key string) int64
	GetFloat64(key string) float64
	GetBool(key string) bool
	GetList(key string) []string
}

func NewViperAdapter

func NewViperAdapter(viper *viper.Viper) Config

NewViperAdapter return new instance of viper adapter to use as logruskit Config.

type FormatterFunc

type FormatterFunc func(config Config) (logrus.Formatter, error)

FormatterFunc should use to define new formatter.

type HookFunc

type HookFunc func(config Config) (logrus.Hook, error)

HookFunc should use to define new hook.

type OutputFunc

type OutputFunc func(config Config) (io.Writer, error)

OutputFunc is function to use for defining new outputs.

type ViperAdapter

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

func (ViperAdapter) Get

func (v ViperAdapter) Get(key string) interface{}

func (ViperAdapter) GetBool

func (v ViperAdapter) GetBool(key string) bool

func (ViperAdapter) GetFloat64

func (v ViperAdapter) GetFloat64(key string) float64

func (ViperAdapter) GetInt64

func (v ViperAdapter) GetInt64(key string) int64

func (ViperAdapter) GetList

func (v ViperAdapter) GetList(key string) []string

func (ViperAdapter) GetString

func (v ViperAdapter) GetString(key string) string

Directories

Path Synopsis
examples
internal
Inspired by logrus_mate.
Inspired by logrus_mate.

Jump to

Keyboard shortcuts

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