logger

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 22, 2022 License: Apache-2.0 Imports: 3 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DocFunc

type DocFunc func(entry *logrus.Entry) interface{}

type ExecFunc

type ExecFunc func(docs interface{}) error

type Hook

type Hook interface {
	logrus.Hook
}

type Level

type Level int8
const (
	// TraceLevel 指定比 debug 更小粒度的日志信息
	TraceLevel Level = iota
	// DebugLevel debug 调试信息, 内容相对更详细
	DebugLevel
	// InfoLevel 默认的日志级别, 通常输出程序正常执行期间的日志
	InfoLevel
	// WarnLevel 警告级别 通常输出值得关注的条目
	WarnLevel
	// ErrorLevel 错误级别 通常是非常值得关注的错误信息
	ErrorLevel
	// FatalLevel 该级别的日志会记录并调用 log.Exit(1), 为最高级别的错误
	FatalLevel
)

func (Level) Enabled

func (l Level) Enabled(lvl Level) bool

Enabled 如果给定的 Level 大于当前 Level 则返回 true

func (Level) String

func (l Level) String() string

type Logger

type Logger interface {
	Init(...Option) error
	Options() *Options
	// WithFields 添加输出固定字段
	WithFields(map[string]interface{})
	// Hook 添加钩子到日志
	Hook(Hook)
	// NewKidHook 创建一个自定义的 Hook 的封装
	NewKidHook(Worker) Hook
	// Log 输出日志
	Log(Level, ...interface{})
	// Logf 输出带格式化的日志
	Logf(Level, string, ...interface{})
}

type Option

type Option func(*Options)

func SetOption

func SetOption(key, value interface{}) Option

func WithFields

func WithFields(fields map[string]interface{}) Option

func WithLevel

func WithLevel(level Level) Option

type Options

type Options struct {
	Level        Level
	LogName      string
	RotationTime time.Duration
	Fields       map[string]interface{}
	Context      context.Context
}

type Worker

type Worker interface {
	Doc() DocFunc
	Exec() ExecFunc
	GetLevels() []logrus.Level
}

Jump to

Keyboard shortcuts

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