xlog

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FieldTraceId = "trace_id"
)

...

Variables

This section is empty.

Functions

func Debug

func Debug(args ...interface{})

Debug ...

func Debugf

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

Debugf ...

func Error

func Error(args ...interface{})

Error ...

func Errorf

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

Errorf ...

func GetTraceCtx

func GetTraceCtx(ctx context.Context, args ...string) context.Context

GetTraceCtx ...

func GetTraceId

func GetTraceId(ctx context.Context) string

GetTraceId ...

func Info

func Info(args ...interface{})

Info ...

func Infof

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

Infof ...

func Trace

func Trace(args ...interface{})

Trace ...

func Tracef

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

Tracef ...

func Warn

func Warn(args ...interface{})

Warn ...

func Warnf

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

Warnf ...

func Writer

func Writer() io.Writer

Writer ...

Types

type Config

type Config struct {
	Type      Type      `yaml:"type"`      // 日志类型
	Level     Level     `yaml:"level"`     // 日志级别
	Formatter Formatter `yaml:"formatter"` // 输出格式
	Filepath  string    `yaml:"filepath"`  // 文件路径
	Stdout    bool      `yaml:"stdout"`    // 输出终端
}

Config ...

type CtxTraceKey

type CtxTraceKey struct{}

...

type Fields

type Fields map[string]interface{}

Fields ...

type Formatter

type Formatter string

Formatter ...

const (
	FormatterJSON Formatter = "json"
	FormatterText Formatter = "text"
)

格式化类型

type Level

type Level string

Level ...

const (
	LevelTrace Level = "trace"
	LevelDebug Level = "debug"
	LevelInfo  Level = "info"
	LevelWarn  Level = "warn"
	LevelError Level = "error"
	LevelFatal Level = "fatal"
	LevelPanic Level = "panic"
)

日志级别

type Logger

type Logger interface {
	Log(level Level, args ...interface{})                 // 记录对应级别的日志
	Logf(level Level, format string, args ...interface{}) // 记录对应级别的日志
	Trace(args ...interface{})                            // 记录 TraceLevel 级别的日志
	Tracef(format string, args ...interface{})            // 格式化并记录 TraceLevel 级别的日志
	Debug(args ...interface{})                            // 记录 DebugLevel 级别的日志
	Debugf(format string, args ...interface{})            // 格式化并记录 DebugLevel 级别的日志
	Info(args ...interface{})                             // 记录 InfoLevel 级别的日志
	Infof(format string, args ...interface{})             // 格式化并记录 InfoLevel 级别的日志
	Warn(args ...interface{})                             // 记录 WarnLevel 级别的日志
	Warnf(format string, args ...interface{})             // 格式化并记录 WarnLevel 级别的日志
	Error(args ...interface{})                            // 记录 ErrorLevel 级别的日志
	Errorf(format string, args ...interface{})            // 格式化并记录 ErrorLevel 级别的日志
	//Fatal(args ...interface{})                            // 记录 FatalLevel 级别的日志
	//Fatalf(format string, args ...interface{})            // 格式化并记录 FatalLevel 级别的日志
	//Panic(args ...interface{})                            // 记录 PanicLevel 级别的日志
	//Panicf(format string, args ...interface{})            // 格式化并记录 PanicLevel 级别的日志
	Writer() io.Writer                          // 返回日志 io.Writer
	Field(key string, value interface{}) Logger // WithField 为日志添加一个上下文数据
	Ctx(ctx context.Context) Logger             // WithContext 为日志添加一个 context
}

Logger ...

func Ctx

func Ctx(ctx context.Context) Logger

Ctx WithContext...

func Field

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

Field WithField...

func NewLogger

func NewLogger(options ...Option) Logger

NewLogger ...

type Option

type Option func(*Config)

Option ...

func WithFile

func WithFile(filepath string) Option

WithFile ...

func WithFormatter

func WithFormatter(formatter Formatter) Option

WithFormatter ...

func WithLevel

func WithLevel(level Level) Option

WithLevel ...

func WithLogrus

func WithLogrus() Option

WithLogrus ...

func WithStdout

func WithStdout(v bool) Option

WithStdout ...

func WithZap

func WithZap() Option

WithZap ...

type Type

type Type int

Type ...

const (
	TypeZap Type = iota
	TypeLogrus
)

日志类型

Jump to

Keyboard shortcuts

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