vlog

package module
v0.9.8 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: MIT Imports: 3 Imported by: 63

README

vlog (github.com/starter-go/vlog)

vlog (virtual-logger) 是一个抽象的日志接口库,相当于 slf4j

源代码: https://github.com/starter-go/vlog

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(fmt string, args ...any)

Debug 输出一条等级为 DEBUG 的日志记录

func Error

func Error(fmt string, args ...any)

Error 输出一条等级为 ERROR 的日志记录

func Fatal

func Fatal(fmt string, args ...any)

Fatal 输出一条等级为 FATAL 的日志记录

func HandleError added in v0.9.8

func HandleError(err error)

HandleError 把错误信息(error)通过日志输出

func HandleErrorX added in v0.9.8

func HandleErrorX(x any)

HandleErrorX 把错误信息(any)通过日志输出

func Info

func Info(fmt string, args ...any)

Info 输出一条等级为 INFO 的日志记录

func IsDebugEnabled

func IsDebugEnabled() bool

IsDebugEnabled 判断是否需要输出等级为 DEBUG 的日志记录

func IsErrorEnabled

func IsErrorEnabled() bool

IsErrorEnabled 判断是否需要输出等级为 ERROR 的日志记录

func IsFatalEnabled

func IsFatalEnabled() bool

IsFatalEnabled 判断是否需要输出等级为 FATAL 的日志记录

func IsInfoEnabled

func IsInfoEnabled() bool

IsInfoEnabled 判断是否需要输出等级为 INFO 的日志记录

func IsTraceEnabled

func IsTraceEnabled() bool

IsTraceEnabled 判断是否需要输出等级为 TRACE 的日志记录

func IsWarnEnabled

func IsWarnEnabled() bool

IsWarnEnabled 判断是否需要输出等级为 WARN 的日志记录

func SetLoggerFactory

func SetLoggerFactory(factory LoggerFactory)

SetLoggerFactory 设置日志工厂

func Trace

func Trace(fmt string, args ...any)

Trace 输出一条等级为 TRACE 的日志记录

func Warn

func Warn(fmt string, args ...any)

Warn 输出一条等级为 WARN 的日志记录

Types

type ConsoleDisplayFilter

type ConsoleDisplayFilter struct {
}

ConsoleDisplayFilter 过滤器

func (*ConsoleDisplayFilter) DoFilter

func (inst *ConsoleDisplayFilter) DoFilter(msg *Message, chain MessageFilterChain)

DoFilter 执行过滤操作

type DateTimeFilter

type DateTimeFilter struct {
}

DateTimeFilter 过滤器

func (*DateTimeFilter) DoFilter

func (inst *DateTimeFilter) DoFilter(msg *Message, chain MessageFilterChain)

DoFilter 执行过滤操作

type ErrorFilter

type ErrorFilter struct {
}

ErrorFilter 过滤器

func (*ErrorFilter) DoFilter

func (inst *ErrorFilter) DoFilter(msg *Message, chain MessageFilterChain)

DoFilter 执行过滤操作

type FormatterFilter

type FormatterFilter struct {
}

FormatterFilter 过滤器

func (*FormatterFilter) DoFilter

func (inst *FormatterFilter) DoFilter(msg *Message, chain MessageFilterChain)

DoFilter 执行过滤操作

type Level

type Level int

Level 表示日志的等级

const (
	ALL   Level = 0 // 把允许的输出等级设置为 ALL,可以输出所有的日志
	TRACE Level = 1
	DEBUG Level = 2
	INFO  Level = 3
	WARN  Level = 4
	ERROR Level = 5
	FATAL Level = 6
	NONE  Level = 99 // 把允许的输出等级设置为 NONE,禁止输出任何等级的日志
)

定义日志等级

func ParseLevel added in v0.9.2

func ParseLevel(str string) (Level, error)

ParseLevel 把字符串解析为 vlog.Level 值

func (Level) String added in v0.9.2

func (l Level) String() string

type LevelFilter

type LevelFilter struct {
	AcceptedLevel Level
}

LevelFilter 过滤器

func (*LevelFilter) DoFilter

func (inst *LevelFilter) DoFilter(msg *Message, chain MessageFilterChain)

DoFilter 执行过滤操作

type Logger

type Logger interface {
	Trace(fmt string, args ...any)
	Debug(fmt string, args ...any)
	Info(fmt string, args ...any)
	Warn(fmt string, args ...any)
	Error(fmt string, args ...any)
	Fatal(fmt string, args ...any)

	IsTraceEnabled() bool
	IsDebugEnabled() bool
	IsInfoEnabled() bool
	IsWarnEnabled() bool
	IsErrorEnabled() bool
	IsFatalEnabled() bool

	ForSender(sender any) Logger
	ForTag(tag string) Logger
}

Logger 是最核心的日志接口

func GetLogger

func GetLogger() Logger

GetLogger 获取日志接口

type LoggerFactory

type LoggerFactory interface {
	Create() Logger
}

LoggerFactory 是用来创建 Logger 的接口

func GetLoggerFactory

func GetLoggerFactory() LoggerFactory

GetLoggerFactory 获取日志工厂

type LoggerHolder added in v0.9.5

type LoggerHolder interface {
	Logger() Logger
}

LoggerHolder 是用来获取 Logger 的接口

type Message

type Message struct {
	Arguments []any
	Error     error
	Format    string
	Level     Level
	Tag       string
	Sender    any
	Text      string
	Timestamp time.Time
}

Message 表示一条日志记录

type MessageFilter

type MessageFilter interface {
	DoFilter(msg *Message, chain MessageFilterChain)
}

MessageFilter 表示一个日志消息过滤器

type MessageFilterChain

type MessageFilterChain interface {
	DoFilter(msg *Message)
}

MessageFilterChain 表示一个日志消息过滤器串

type MessageFilterChainBuilder

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

MessageFilterChainBuilder 用来创建一个 MessageFilterChain

func (*MessageFilterChainBuilder) AddFilter

func (inst *MessageFilterChainBuilder) AddFilter(filter MessageFilter)

AddFilter 添加一个过滤器

func (*MessageFilterChainBuilder) Create

Create 创建 MessageFilterChain

type MessageFilterGroup added in v0.9.3

type MessageFilterGroup interface {
	GetFilterChain() MessageFilterChain
}

MessageFilterGroup 表示一个日志消息过滤器组

type MessageFilterRegistration added in v0.9.3

type MessageFilterRegistration struct {
	Order  int
	Name   string
	Filter MessageFilter
}

MessageFilterRegistration 表示一个日志过滤器注册信息

type MessageFilterRegistry added in v0.9.3

type MessageFilterRegistry interface {
	ListLogFilterRegistration() []*MessageFilterRegistration
}

MessageFilterRegistry 表示一个日志过滤器注册器

type SimpleLogger

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

SimpleLogger 实现一个简单的日志接口

func (*SimpleLogger) Debug

func (inst *SimpleLogger) Debug(fmt string, args ...interface{})

Debug ...

func (*SimpleLogger) Error

func (inst *SimpleLogger) Error(fmt string, args ...interface{})

Error ...

func (*SimpleLogger) Fatal

func (inst *SimpleLogger) Fatal(fmt string, args ...interface{})

Fatal ...

func (*SimpleLogger) ForSender added in v0.9.4

func (inst *SimpleLogger) ForSender(sender any) Logger

ForSender 虽然但是 SimpleLogger 不支持 sender

func (*SimpleLogger) ForTag added in v0.9.4

func (inst *SimpleLogger) ForTag(tag string) Logger

ForTag 虽然但是 SimpleLogger 不支持 tag

func (*SimpleLogger) Info

func (inst *SimpleLogger) Info(fmt string, args ...interface{})

Info ...

func (*SimpleLogger) IsDebugEnabled

func (inst *SimpleLogger) IsDebugEnabled() bool

IsDebugEnabled ...

func (*SimpleLogger) IsErrorEnabled

func (inst *SimpleLogger) IsErrorEnabled() bool

IsErrorEnabled ...

func (*SimpleLogger) IsFatalEnabled

func (inst *SimpleLogger) IsFatalEnabled() bool

IsFatalEnabled ...

func (*SimpleLogger) IsInfoEnabled

func (inst *SimpleLogger) IsInfoEnabled() bool

IsInfoEnabled ...

func (*SimpleLogger) IsTraceEnabled

func (inst *SimpleLogger) IsTraceEnabled() bool

IsTraceEnabled ...

func (*SimpleLogger) IsWarnEnabled

func (inst *SimpleLogger) IsWarnEnabled() bool

IsWarnEnabled ...

func (*SimpleLogger) Trace

func (inst *SimpleLogger) Trace(fmt string, args ...interface{})

Trace ...

func (*SimpleLogger) Warn

func (inst *SimpleLogger) Warn(fmt string, args ...interface{})

Warn ...

type SimpleLoggerFactory

type SimpleLoggerFactory struct {
	AcceptedLevel Level
}

SimpleLoggerFactory 实现一个简易的日志工厂

func (*SimpleLoggerFactory) Create

func (inst *SimpleLoggerFactory) Create() Logger

Create 创建日志接口

type Stringer

type Stringer interface {
	String() string
}

Stringer 表示一个可字符化的接口

Directories

Path Synopsis
src

Jump to

Keyboard shortcuts

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