log

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(msg string, fields ...Field)

Debug 打印调试级别日志

func Error

func Error(msg string, fields ...Field)

Error 打印错误级别日志

func Info

func Info(msg string, fields ...Field)

Info 打印信息级别日志

func SetLogger

func SetLogger(logger Logger)

SetLogger 设置全局日志记录器

func Warn

func Warn(msg string, fields ...Field)

Warn 打印警告级别日志

Types

type Field

type Field struct {
	Key   string
	Value interface{}
}

Field 是日志字段

func Any

func Any(key string, value interface{}) Field

Any 创建一个任意类型字段

func Bool

func Bool(key string, value bool) Field

Bool 创建一个布尔字段

func Err

func Err(err error) Field

Err 创建一个错误字段

func Float64

func Float64(key string, value float64) Field

Float64 创建一个浮点数字段

func Int

func Int(key string, value int) Field

Int 创建一个整数字段

func String

func String(key string, value string) Field

String 创建一个字符串字段

type Format

type Format string

Format 表示日志格式

const (
	// TextFormat 表示文本格式
	TextFormat Format = "text"
	// JSONFormat 表示JSON格式
	JSONFormat Format = "json"
)

type Level

type Level int8

Level 表示日志级别

const (
	// DebugLevel 表示调试级别
	DebugLevel Level = iota - 1
	// InfoLevel 表示信息级别
	InfoLevel
	// WarnLevel 表示警告级别
	WarnLevel
	// ErrorLevel 表示错误级别
	ErrorLevel
	// FatalLevel 表示致命级别
	FatalLevel
)

type Logger

type Logger interface {
	// Info 打印信息级别日志
	Info(msg string, fields ...Field)
	// Warn 打印警告级别日志
	Warn(msg string, fields ...Field)
	// Error 打印错误级别日志
	Error(msg string, fields ...Field)
	// Debug 打印调试级别日志
	Debug(msg string, fields ...Field)
	// WithContext 返回带有上下文的日志记录器
	WithContext(ctx context.Context) Logger
}

Logger 是日志接口

var DefaultLogger Logger = NewStdLogger()

DefaultLogger 是默认的日志记录器

func New

func New(opts ...Option) Logger

New 创建一个日志记录器

func NewStdLogger

func NewStdLogger() Logger

NewStdLogger 创建一个标准日志记录器

func NewZapLogger

func NewZapLogger(opts *options) Logger

NewZapLogger 创建基于zap的日志记录器

func WithContext

func WithContext(ctx context.Context) Logger

WithContext 返回带有上下文的日志记录器

type Option

type Option func(*options)

Option 是Logger配置选项

func WithCaller

func WithCaller(enabled bool) Option

WithCaller 设置是否打印调用者信息

func WithFormat

func WithFormat(format Format) Option

WithFormat 设置日志格式

func WithLevel

func WithLevel(level Level) Option

WithLevel 设置日志级别

func WithOutput

func WithOutput(output string) Option

WithOutput 设置日志输出

Jump to

Keyboard shortcuts

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