wlog

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2022 License: Apache-2.0 Imports: 12 Imported by: 6

Documentation

Index

Constants

View Source
const (
	DebugLevel = 1 << 0
	InfoLevel  = 1 << 1
	WarnLevel  = 1 << 2
	ErrorLevel = 1 << 3
	PanicLevel = 1 << 4
	FatalLevel = 1 << 5
)
View Source
const (
	FmtEmptySeparate = ""
)

Variables

View Source
var LevelNameMapping = map[Level]string{
	DebugLevel: "DEBUG",
	InfoLevel:  "INFO",
	WarnLevel:  "WARN",
	ErrorLevel: "ERROR",
	PanicLevel: "PANIC",
	FatalLevel: "FATAL",
}

Functions

func Debug

func Debug(args ...interface{})

std logger

func Debugf

func Debugf(format string, args ...interface{})

func Error

func Error(args ...interface{})

func Errorf

func Errorf(format string, args ...interface{})

func Fatal

func Fatal(args ...interface{})

func Fatalf

func Fatalf(format string, args ...interface{})

func Info

func Info(args ...interface{})

func Infof

func Infof(format string, args ...interface{})

func New

func New(opts ...OptionFunc) *logger

func Panic

func Panic(args ...interface{})

func Panicf

func Panicf(format string, args ...interface{})

func SetStdOptions

func SetStdOptions(opts ...OptionFunc)

设置默认的 std 的日志输出器

func StdLogger

func StdLogger() *logger

func Warn

func Warn(args ...interface{})

func Warnf

func Warnf(format string, args ...interface{})

func Writer

func Writer() io.Writer

Types

type Attribute

type Attribute color.Attribute
const (
	Reset Attribute = iota
	Bold
	Faint
	Italic
	Underline
	BlinkSlow
	BlinkRapid
	ReverseVideo
	Concealed
	CrossedOut
)

Base attributes

const (
	FgBlack Attribute = iota + 30
	FgRed
	FgGreen
	FgYellow
	FgBlue
	FgMagenta
	FgCyan
	FgWhite
)

Foreground text colors

const (
	FgHiBlack Attribute = iota + 90
	FgHiRed
	FgHiGreen
	FgHiYellow
	FgHiBlue
	FgHiMagenta
	FgHiCyan
	FgHiWhite
)

Foreground Hi-Intensity text colors

const (
	BgBlack Attribute = iota + 40
	BgRed
	BgGreen
	BgYellow
	BgBlue
	BgMagenta
	BgCyan
	BgWhite
)

Background text colors

const (
	BgHiBlack Attribute = iota + 100
	BgHiRed
	BgHiGreen
	BgHiYellow
	BgHiBlue
	BgHiMagenta
	BgHiCyan
	BgHiWhite
)

Background Hi-Intensity text colors

type Entry

type Entry struct {
	Buffer *bytes.Buffer
	Level  Level
	Time   time.Time
	File   string
	Line   int
	Func   string
	Format string
	Args   []interface{}
	// contains filtered or unexported fields
}

func (*Entry) Write

func (e *Entry) Write(level Level, format string, args ...interface{})

type Formatter

type Formatter interface {
	Format(entry *Entry) error
}

格式化编码器

func JsonFormatter

func JsonFormatter(ignoreBasicFields bool) Formatter

type Hook

type Hook interface {
	// hook 处理
	Handler(level Level, content []byte) error
	// 处理 hook err 中发生的错误
	DealWithErr(err error)
}

func ShortHook

func ShortHook(
	handler func(level Level, content []byte) error,
	dealErr func(err error),
) Hook

简单的 hook 新建接口

type HookGroup

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

更高级的 hook,用来直接处理一组 hook

func (*HookGroup) DealWithErr

func (s *HookGroup) DealWithErr(err error)

处理 hook err 中发生的错误

func (*HookGroup) Handler

func (s *HookGroup) Handler(logLevel Level, content []byte) error

type Level

type Level uint8

func (*Level) UnmarshalText

func (l *Level) UnmarshalText(text []byte) error

type OptionFunc

type OptionFunc func(*options)

func WithDisPlayLevel

func WithDisPlayLevel(level Level) OptionFunc

func WithDisableCaller

func WithDisableCaller(caller bool) OptionFunc

关闭堆栈调用

func WithFormatter

func WithFormatter(formatter Formatter) OptionFunc

func WithHook

func WithHook(level Level, hook Hook) OptionFunc

func WithHookGroup

func WithHookGroup(logLevel Level, hooks ...Hook) OptionFunc

hook 组合

func WithLogLevelColor

func WithLogLevelColor(level Level, font Attribute) OptionFunc

func WithOutput

func WithOutput(op io.Writer) OptionFunc

func WithStdDisPlayLevel

func WithStdDisPlayLevel(level Level) OptionFunc

type SimpleHook

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

func (*SimpleHook) DealWithErr

func (s *SimpleHook) DealWithErr(err error)

处理 hook err 中发生的错误

func (*SimpleHook) Handler

func (s *SimpleHook) Handler(logLevel Level, content []byte) error

hook 处理

type TextFormatter

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

func (*TextFormatter) Format

func (t *TextFormatter) Format(entry *Entry) error

Jump to

Keyboard shortcuts

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