log

package
v0.0.0-...-e5dec72 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	// DebugLevel logs are typically voluminous, and are usually disabled in  production.
	DebugLevel = zapcore.DebugLevel
	// InfoLevel is the default logging priority.
	InfoLevel = zapcore.InfoLevel
	// WarnLevel logs are more important than Info, but don't need individual human review.
	WarnLevel = zapcore.WarnLevel
	// ErrorLevel logs are high-priority. If an application is running smoothly,
	// it shouldn't generate any error-level logs.
	ErrorLevel = zapcore.ErrorLevel
	//FatalLevel logs a message, then calls os.Exit(1).
	FatalLevel = zapcore.FatalLevel
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry interface {
	Context() (ctx context.Context)
	AppendField(field zap.Field) (err error)
	GetFields() (fields []zap.Field)
}

type FieldLogger

type FieldLogger interface {
	Debug(msg string, fields ...zap.Field)
	Info(msg string, fields ...zap.Field)
	Warn(msg string, fields ...zap.Field)
	Error(msg string, fields ...zap.Field)
	Fatal(msg string, fields ...zap.Field)
}

type Helper

type Helper interface {
	WithContext(ctx context.Context) (logger FieldLogger)
}

Helper logger helper

func NewHelper

func NewHelper(logger *zap.Logger, opt ...Option) Helper
Example
var logger, err = zaplog.NewZapLogger(&config.ZapConfig{})
if err != nil {
	stdLog.Fatal("err ", err)
}
var helper Helper = NewHelper(logger)
helper.WithContext(context.Background()).Info("hello")
helper.WithContext(context.TODO()).Error("error ", zap.String("error", "error info"))
Output:

type Hook

type Hook interface {
	Levels() (lvs []zapcore.Level)
	Fire(e Entry) (err error)
}

type LevelHooks

type LevelHooks map[zapcore.Level][]Hook

func (LevelHooks) Add

func (hooks LevelHooks) Add(hook Hook)

Add hook plugin

func (LevelHooks) Fire

func (hooks LevelHooks) Fire(level zapcore.Level, entry Entry) (err error)

Fire execute hook plugin, if get error return err else return nil

type Option

type Option func(c *ZapHelperBuilder)

func AddHook

func AddHook(hook Hook) Option

type ZapHelperBuilder

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

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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