logger

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigPrefix = "LOGGER"

ConfigPrefix defines the configuration prefix

Functions

This section is empty.

Types

type Field

type Field interface {
	Key() string
	Val() interface{}
}

Field represents the interface of logger field

func E

func E(err error) Field

E helps to create an error field

func F

func F(key string, value interface{}) Field

F helps to create a logger field

func G

func G(name string, fields ...Field) Field

G create an anonymous struct to group fields

func S

func S(value interface{}) []Field

S helps to create a struct field

type Logger

type Logger interface {
	AddDefaultField(Field)

	Debug(msg string, fields ...Field)
	Info(msg string, fields ...Field)
	Warn(msg string, fields ...Field)
	Error(msg string, fields ...Field)
	Fatal(msg string, fields ...Field)
	Panic(msg string, fields ...Field)

	Infof(msg string, data ...interface{})
	Warningf(msg string, data ...interface{})
	Errorf(msg string, data ...interface{})
}

Logger represents the interface of logger

func New

func New(opts ...Option) (Logger, error)

New creates a new logger instance

type Option

type Option func(*Options)

Option represents an option

func DefaultFields

func DefaultFields(fields ...Field) Option

DefaultFields returns default fields option

func Format

func Format(format string) Option

Format returns format option

func InstName

func InstName(instName string) Option

InstName returns instance name option

func InstVersion

func InstVersion(instVersion string) Option

InstVersion returns instance option

func Level

func Level(level string) Option

Level returns level option

type Options

type Options struct {
	Level  string `default:"info" envconfig:"LEVEL"`
	Format string `default:"json" envconfig:"FORMAT"`

	InstName    string `default:"unknown" envconfig:"INST_NAME"`
	InstVersion string `default:"unknown" envconfig:"INST_VERSION"`

	DefaultFields []Field `ignored:"true" json:"-"`
}

Options represents the logger options

Jump to

Keyboard shortcuts

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