etlog

package module
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

README

etlog

etlog is a log component for go.

Features

  • Support log level
  • Stdout and file appender
  • log markers support

Quick start

  1. Simple usage
etlog.Log.Info("Hello World")

It will output the log into stdout device(console log).

  1. Using log config
logger, err := etlog.NewEtLogger(etlog.SetConfigPath("log.yaml"))
if err != nil {
    panic(err)
}
logger.Debug("hello")
logger.Info("world")

the log config file please refer to: example/log.yaml

  1. Using fieds
etlog.Log.WithError(fmt.Errorf("oops")).
    WithField("key", "word").
    WithField("now", time.Now()).
    Error("something wrong happened")

the WithField method will help you print K-V fields into log.

  1. Using markers
etlog.Log.WithMarkers("trace").Data("hello world")

Because we support different log handler, to determine which handler the content will be output, we use marker to route it. Such as the example, when we use trace as marker of log, then the content will be processed by handler marked as trace.

Documentation

Index

Constants

View Source
const (
	DefaultConfigPath = "log.yaml"
	BaseSkip          = 5
)

Variables

This section is empty.

Functions

func SetDefaultLog

func SetDefaultLog(l Logger)

Types

type EtLogger

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

func NewEtLogger

func NewEtLogger(options ...OptionFunc) (*EtLogger, error)

func (*EtLogger) Data

func (el *EtLogger) Data(msg string)

func (*EtLogger) Debug

func (el *EtLogger) Debug(msg string)

func (*EtLogger) Enable

func (el *EtLogger) Enable(level core.Level) bool

func (*EtLogger) Error

func (el *EtLogger) Error(msg string)

func (*EtLogger) Fatal

func (el *EtLogger) Fatal(msg string)

func (*EtLogger) Info

func (el *EtLogger) Info(msg string)

func (*EtLogger) Warn

func (el *EtLogger) Warn(msg string)

func (*EtLogger) WithError

func (el *EtLogger) WithError(err error) Logger

func (*EtLogger) WithField

func (el *EtLogger) WithField(field string, v interface{}) Logger

func (*EtLogger) WithFields

func (el *EtLogger) WithFields(fields core.Fields) Logger

func (*EtLogger) WithMarkers

func (el *EtLogger) WithMarkers(markers ...string) Logger

type Handlers

type Handlers = []handler.Handler

type Logger

type Logger interface {
	Debug(msg string)
	Info(msg string)
	Data(msg string)
	Warn(msg string)
	Error(msg string)
	Fatal(msg string)
	WithField(field string, v interface{}) Logger
	WithFields(fields core.Fields) Logger
	WithError(err error) Logger
	WithMarkers(markers ...string) Logger
	Enable(level core.Level) bool
}
var Log Logger

type OptionFunc

type OptionFunc func(logger *EtLogger) error

func SetConfigPath

func SetConfigPath(configPath string) OptionFunc

func SetErrorLog

func SetErrorLog(errLog opt.Printfer) OptionFunc

func SetInfoLog

func SetInfoLog(infoLog opt.Printfer) OptionFunc

func SetPostLog

func SetPostLog(postLog ...opt.LogFunc) OptionFunc

func SetPreLog

func SetPreLog(preLog ...opt.LogFunc) OptionFunc

func SetSourceSkip

func SetSourceSkip(skip uint) OptionFunc

Directories

Path Synopsis
common

Jump to

Keyboard shortcuts

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