log

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2022 License: MIT Imports: 11 Imported by: 15

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(a ...interface{})

Debug 打印调试日志

func Debugf

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

Debugf 打印调试模板日志

func Error

func Error(a ...interface{})

Error 打印错误日志

func Errorf

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

Errorf 打印错误模板日志

func Fatal

func Fatal(a ...interface{})

Fatal 打印致命错误日志

func Fatalf

func Fatalf(format string, a ...interface{})

Fatalf 打印致命错误模板日志

func GetFrames added in v0.0.3

func GetFrames(skip int, depth StacktraceDepth) []runtime.Frame

func GetStacktrace added in v0.0.3

func GetStacktrace(skip int, depth StacktraceDepth) *stacktrace

func Info

func Info(a ...interface{})

Info 打印信息日志

func Infof

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

Infof 打印信息模板日志

func NewWriter added in v0.0.3

func NewWriter(opts WriterOptions) (io.Writer, error)

func Panic added in v0.0.3

func Panic(a ...interface{})

Panic 打印Panic日志

func Panicf added in v0.0.3

func Panicf(format string, a ...interface{})

Fatalf 打印Panic模板日志

func SetLogger

func SetLogger(logger Logger)

SetLogger 设置日志记录器

func Warn

func Warn(a ...interface{})

Warn 打印警告日志

func Warnf

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

Warnf 打印警告模板日志

Types

type CallerFormat added in v0.0.3

type CallerFormat int

调用则格式

const (
	CallerShortPath CallerFormat = iota // 调用者短路径
	CallerFullPath                      // 调用者全路径
)

type CutRule added in v0.0.3

type CutRule int

日志切割规则

const (
	CutByYear   CutRule = iota + 1 // 按照年切割
	CutByMonth                     // 按照月切割
	CutByDay                       // 按照日切割
	CutByHour                      // 按照时切割
	CutByMinute                    // 按照分切割
	CutBySecond                    // 按照秒切割
)

type Entity added in v0.0.3

type Entity struct {
	Color   int
	Level   Level
	Time    string
	Caller  string
	Message string
	Frames  []runtime.Frame
	// contains filtered or unexported fields
}

func (*Entity) Free added in v0.0.3

func (e *Entity) Free()

func (*Entity) Log added in v0.0.3

func (e *Entity) Log()

type EntityPool added in v0.0.3

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

type Format added in v0.0.3

type Format int

日志输出格式

const (
	TextFormat Format = iota // 文本格式
	JsonFormat               // JSON格式
)

type Level

type Level int

日志级别

const (
	DebugLevel Level = iota + 1 // DEBUG
	InfoLevel                   // INFO
	WarnLevel                   // WARN
	ErrorLevel                  // ERROR
	FatalLevel                  // FATAL
	PanicLevel                  // PANIC
)

func (Level) String

func (l Level) String() string

type Logger

type Logger interface {
	// Debug 打印调试日志
	Debug(a ...interface{})
	// Debugf 打印调试模板日志
	Debugf(format string, a ...interface{})
	// Info 打印信息日志
	Info(a ...interface{})
	// Infof 打印信息模板日志
	Infof(format string, a ...interface{})
	// Warn 打印警告日志
	Warn(a ...interface{})
	// Warnf 打印警告模板日志
	Warnf(format string, a ...interface{})
	// Error 打印错误日志
	Error(a ...interface{})
	// Errorf 打印错误模板日志
	Errorf(format string, a ...interface{})
	// Fatal 打印致命错误日志
	Fatal(a ...interface{})
	// Fatalf 打印致命错误模板日志
	Fatalf(format string, a ...interface{})
	// Panic 打印Panic日志
	Panic(a ...interface{})
	// Panicf 打印Panic模板日志
	Panicf(format string, a ...interface{})
}

func GetLogger

func GetLogger() Logger

GetLogger 获取日志记录器

type Option

type Option func(o *options)

func WithCallerFormat added in v0.0.3

func WithCallerFormat(format CallerFormat) Option

WithCallerFormat 设置调用者格式

func WithCallerSkip added in v0.0.3

func WithCallerSkip(skip int) Option

WithCallerSkip 设置调用者跳过的层级深度

func WithEnableLeveledStorage added in v0.0.3

func WithEnableLeveledStorage(enable bool) Option

WithEnableLeveledStorage 设置启用文件分级存储 启用后,日志将进行分级存储,大一级的日志将存储于小于等于自身的日志级别文件中 例如:InfoLevel级的日志将存储于due.debug.20220910.log、due.info.20220910.log两个日志文件中

func WithFileCutRule added in v0.0.3

func WithFileCutRule(cutRule CutRule) Option

WithFileCutRule 设置文件切割规则

func WithFileMaxAge added in v0.0.3

func WithFileMaxAge(maxAge time.Duration) Option

WithFileMaxAge 设置文件最大留存时间

func WithFileMaxSize added in v0.0.3

func WithFileMaxSize(size int64) Option

WithFileMaxSize 设置输出的单个文件尺寸限制

func WithOutFile added in v0.0.3

func WithOutFile(file string) Option

WithOutFile 设置输出的文件路径

func WithOutFormat added in v0.0.3

func WithOutFormat(format Format) Option

WithOutFormat 设置输出的日志格式

func WithOutLevel added in v0.0.3

func WithOutLevel(level Level) Option

WithOutLevel 设置输出的最低日志级别

func WithStackLevel added in v0.0.3

func WithStackLevel(level Level) Option

WithStackLevel 设置堆栈的最小输出级别

func WithTimestampFormat added in v0.0.3

func WithTimestampFormat(format string) Option

WithTimestampFormat 设置时间格式

type StacktraceDepth added in v0.0.3

type StacktraceDepth int
const (
	// stacktraceFirst captures only the first frame.
	StacktraceFirst StacktraceDepth = iota

	// stacktraceFull captures the entire call stack, allocating more
	// storage for it if needed.
	StacktraceFull
)

type Std added in v0.0.3

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

func NewLogger

func NewLogger(opts ...Option) *Std

func (*Std) Debug added in v0.0.3

func (l *Std) Debug(a ...interface{})

Debug 打印调试日志

func (*Std) Debugf added in v0.0.3

func (l *Std) Debugf(format string, a ...interface{})

Debugf 打印调试模板日志

func (*Std) Entity added in v0.0.3

func (l *Std) Entity(level Level, a ...interface{}) *Entity

构建日志实体

func (*Std) Error added in v0.0.3

func (l *Std) Error(a ...interface{})

Error 打印错误日志

func (*Std) Errorf added in v0.0.3

func (l *Std) Errorf(format string, a ...interface{})

Errorf 打印错误模板日志

func (*Std) Fatal added in v0.0.3

func (l *Std) Fatal(a ...interface{})

Fatal 打印致命错误日志

func (*Std) Fatalf added in v0.0.3

func (l *Std) Fatalf(format string, a ...interface{})

Fatalf 打印致命错误模板日志

func (*Std) Info added in v0.0.3

func (l *Std) Info(a ...interface{})

Info 打印信息日志

func (*Std) Infof added in v0.0.3

func (l *Std) Infof(format string, a ...interface{})

Infof 打印信息模板日志

func (*Std) Panic added in v0.0.3

func (l *Std) Panic(a ...interface{})

Panic 打印Panic日志

func (*Std) Panicf added in v0.0.3

func (l *Std) Panicf(format string, a ...interface{})

Panicf 打印Panic模板日志

func (*Std) Warn added in v0.0.3

func (l *Std) Warn(a ...interface{})

Warn 打印警告日志

func (*Std) Warnf added in v0.0.3

func (l *Std) Warnf(format string, a ...interface{})

Warnf 打印警告模板日志

type WriterOptions added in v0.0.3

type WriterOptions struct {
	Path    string
	Level   Level
	MaxAge  time.Duration
	MaxSize int64
	CutRule CutRule
}

Directories

Path Synopsis
aliyun module
logrus module
tencent module
zap module

Jump to

Keyboard shortcuts

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