logx

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// InfoLevel logs everything
	InfoLevel uint32 = iota
	// ErrorLevel includes errors
	ErrorLevel
	// StatLevel includes stat
	StatLevel
	// SevereLevel only log severe messages
	SevereLevel
)

Variables

This section is empty.

Functions

func Close

func Close() error

func Error

func Error(v ...interface{})

Error writes v into error log.

func Errorf

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

Errorf writes v with format into error log.

func Errorw

func Errorw(msg string, fields ...LogField)

Errorw writes msg along with fields into error log.

func Info

func Info(v ...interface{})

Info writes v into error log.

func Infof

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

Infof writes v with format into error log.

func Infow

func Infow(msg string, fields ...LogField)

Infow writes msg along with fields into error log.

func SetLevel

func SetLevel(c gofkConfs.LogConfig)

SetLevel sets the logging level. It can be used to suppress some logs.

func SetUp

func SetUp(c gofkConfs.LogConfig) error

SetUp sets up the logx.

func SetWriter

func SetWriter(w Writer)

func Slow

func Slow(v ...interface{})

Slow writes v into slow log.

func Slowf

func Slowf(format string, v ...interface{})

Slowf writes v with format into slow log.

func Sloww

func Sloww(msg string, fields ...LogField)

Sloww writes msg along with fields into slow log.

func Stat

func Stat(v ...interface{})

Stat writes v into error log.

func Statf

func Statf(format string, v ...interface{})

Statf writes v with format into error log.

func Statw

func Statw(msg string, fields ...LogField)

Statw writes msg along with fields into error log.

Types

type DailyRotateRule

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

DailyRotateRule 日志规则实现(按天)

func (*DailyRotateRule) BackupFileName

func (r *DailyRotateRule) BackupFileName() string

BackupFileName 形成备份文件的文件名 使用 filename、delimiter 和当前日期(通过调用 getNowDate() 函数获取)按照一定的格式组合起来。

func (*DailyRotateRule) MarkRotated

func (r *DailyRotateRule) MarkRotated()

MarkRotated 调用 getNowDate() 函数来获取当前的日期,并将其赋值给 r 的 rotatedTime 字段。 这个操作表示日志文件已经被轮转,并将轮转的时间更新为当前时间。

func (*DailyRotateRule) OutDatedFiles

func (r *DailyRotateRule) OutDatedFiles() []string

OutDatedFiles 用于返回超过保留天数的日志文件列表。

func (*DailyRotateRule) ShallRotate

func (r *DailyRotateRule) ShallRotate() bool

ShallRotate 判断是否需要进行切割,通过日期时间判断 @response true 需要切割 @response false 不需要切割

type LogField

type LogField struct {
	Key   string
	Value interface{}
}

func Field

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

func WithField added in v1.0.3

func WithField(k string, v interface{}) LogField

WithField k-v

type LogOptionFunc

type LogOptionFunc func(options *logOptions)

func WithCoolDownMillis

func WithCoolDownMillis(millis int) LogOptionFunc

WithCoolDownMillis customizes logging on writing call stack interval.

func WithGzip

func WithGzip() LogOptionFunc

WithGzip customizes logging to automatically gzip the log files.

func WithKeepDays

func WithKeepDays(days int) LogOptionFunc

WithKeepDays customizes logging to keep logs with days.

type LoggerInter

type LoggerInter interface {
	Error(...interface{})
	Errorf(string, ...interface{})
	Errorw(string, ...LogField)

	Info(...interface{})
	Infof(string, ...interface{})
	Infow(string, ...LogField)

	Slow(...interface{})
	Slowf(string, ...interface{})
	Sloww(string, ...LogField)

	WithContext(ctx context.Context) LoggerInter
	WithDuration(time.Duration) LoggerInter
}

func WithContext

func WithContext(ctx context.Context) LoggerInter

type RotateLogger

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

RotateLogger 结构体是一个日志切割的实现。 需要实现 io.{Closer,Writer} 接口方法,从而实现写和关操作。

func NewLogger

func NewLogger(filename string, rule RotateRule, compress bool) (*RotateLogger, error)

func (*RotateLogger) Close

func (l *RotateLogger) Close() error

Close 关闭文件 RotateLogger,trait io.Closer

func (*RotateLogger) Write

func (l *RotateLogger) Write(data []byte) (int, error)

Writer 写入文件 RotateLogger, trait io.Writer

type RotateRule

type RotateRule interface {
	BackupFileName() string
	MarkRotated()
	OutDatedFiles() []string
	ShallRotate() bool
}

func DefaultRotateRule

func DefaultRotateRule(filename, delimiter string, days int, gzip bool) RotateRule

type Writer

type Writer interface {
	Close() error
	Error(v interface{}, fields ...LogField)
	Info(v interface{}, fields ...LogField)
	Stat(v interface{}, fields ...LogField)
	Slow(v interface{}, fields ...LogField)
	Write(p []byte) (int, error)
}

func NewWriter

func NewWriter(w io.Writer) Writer

Jump to

Keyboard shortcuts

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