logger

package
v0.0.0-...-4595926 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Formatter

type Formatter interface {
	Format(level Level, msg string) ([]byte, error)
}

Formatter 日志格式化接口

type JSONFormatter

type JSONFormatter struct{}

func (*JSONFormatter) Format

func (f *JSONFormatter) Format(level Level, msg string) ([]byte, error)

type Level

type Level uint32

Level 日志级别类型

const (
	LevelDebug Level = iota
	LevelInfo
	LevelWarn
	LevelError
	LevelFatal
)

func (Level) String

func (level Level) String() string

type Logger

type Logger interface {
	Debug(args ...interface{})
	Debugf(format string, args ...interface{})

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

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

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

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

	// 控制接口
	SetLevel(Level)
	GetLevel() Level
}

Logger 核心接口

func New

func New(opts ...Option) Logger

New 创建Logger实例

type Option

type Option func(*loggerImpl)

Option 配置函数类型

func WithFormatter

func WithFormatter(f Formatter) Option

WithFormatter 设置日志格式化器

func WithLevel

func WithLevel(level Level) Option

WithLevel 设置日志级别

func WithOutput

func WithOutput(w io.Writer) Option

WithOutput 设置日志输出

type TextFormatter

type TextFormatter struct{}

func (*TextFormatter) Format

func (f *TextFormatter) Format(level Level, msg string) ([]byte, error)

Jump to

Keyboard shortcuts

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