elog

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2022 License: MIT Imports: 6 Imported by: 4

README

elog

分日志级别的 Golang log 库, 支持设置日志项的顺序

Documentation

Index

Constants

View Source
const (
	FatalLevel logLevel = iota // 致命的错误: 表明程序遇到了致命的错误,必须马上终止运行。
	PanicLevel                 // 致命的错误: 表明程序遇到了致命的错误,可以不马上终止运行,依赖 recover()。
	ErrorLevel                 // 状态错误: 该错误发生后程序仍然可以运行,但是极有可能运行在某种非正常的状态下,导致无法完成全部既定的功能。
	WarnLevel                  // 警告信息: 程序处理中遇到非法数据或者某种可能的错误。该错误是一过性的、可恢复的,不会影响程序继续运行,程序仍处在正常状态。
	InfoLevel                  // 报告程序进度和状态信息: 一般这种信息都是一过性的,不会大量反复输出。例如:连接商用库成功后,可以打印一条连库成功的信息,便于跟踪程序进展信息。
	DebugLevel                 // 终端查看、在线调试: 默认情况下会打印到终端输出,但是不会归档到日志文件。因此,一般用于开发者在程序当前启动窗口上,查看日志流水信息。
	TraceLevel                 // 在线调试: 默认情况下,既不打印到终端也不输出到文件。此时,对程序运行效率几乎不产生影响。常用语 for 循环中调试
	Discard
)
View Source
const (
	Ldate = 1 << iota
	Ltime
	Lmicroseconds
	LUTC
	Llongfile
	Lshortfile
	Lmsgprefix
	Lmsgcolor
	Llevel
	LstdFlags = Ldate | Ltime | Lshortfile | Llevel
)

Flag set include setting of date, time, path, prefix, level, msg

View Source
const (
	OrderDate   logOrder = "Date"
	OrderTime   logOrder = "Time"
	OrderLevel  logOrder = "Level"
	OrderPrefix logOrder = "Prefix"
	OrderPath   logOrder = "Path"
	OrderMsg    logOrder = "Message"
)

Variables

View Source
var (
	// Getter & Setter
	Output    = std.Output
	Level     = std.Level
	Name      = std.Name
	Prefix    = std.Prefix
	Order     = std.Order
	Flag      = std.Flag
	SetOutput = std.SetOutput
	SetLevel  = std.SetLevel
	SetName   = std.SetName
	SetPrefix = std.SetPrefix
	SetOrder  = std.SetOrder
	SetFlag   = std.SetFlag

	// Method Set
	Fatal = std.Fatal
	Panic = std.Panic
	Error = std.Error
	Warn  = std.Warn
	Info  = std.Info
	Debug = std.Debug
	Trace = std.Trace

	Fatalf = std.Fatalf
	Panicf = std.Panicf
	Errorf = std.Errorf
	Warnf  = std.Warnf
	Infof  = std.Infof
	Debugf = std.Debugf
	Tracef = std.Tracef
)

Functions

This section is empty.

Types

type Log

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

func Default

func Default() *Log

============================== Default global object ======================================

func Extend

func Extend(options ...LogOption) *Log

func New

func New(w io.Writer, level logLevel, options ...LogOption) *Log

func (*Log) AddFlag added in v1.1.0

func (l *Log) AddFlag(flag int)

Manipulate Flag

func (*Log) Debug

func (l *Log) Debug(v ...interface{})

func (*Log) Debugf

func (l *Log) Debugf(format string, v ...interface{})

func (*Log) Error

func (l *Log) Error(v ...interface{})

func (*Log) Errorf

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

func (*Log) Extend added in v1.1.0

func (parent *Log) Extend(options ...LogOption) *Log

func (*Log) Fatal

func (l *Log) Fatal(v ...interface{})

Method Set

func (*Log) Fatalf

func (l *Log) Fatalf(format string, v ...interface{})

func (*Log) Flag

func (l *Log) Flag() int

func (*Log) Info

func (l *Log) Info(v ...interface{})

func (*Log) Infof

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

func (*Log) Level

func (l *Log) Level() logLevel

func (*Log) Name

func (l *Log) Name() string

func (*Log) Order added in v1.1.0

func (l *Log) Order() []logOrder

func (*Log) Out

func (l *Log) Out(calldepth int, level logLevel, msg string) error

Out is a core method

func (*Log) Output

func (l *Log) Output() io.Writer

Getter & Setter

func (*Log) Panic

func (l *Log) Panic(v ...interface{})

func (*Log) Panicf

func (l *Log) Panicf(format string, v ...interface{})

func (*Log) Prefix

func (l *Log) Prefix() string

func (*Log) SetFlag

func (l *Log) SetFlag(flag int)

func (*Log) SetLevel

func (l *Log) SetLevel(level logLevel)

func (*Log) SetName

func (l *Log) SetName(name string)

func (*Log) SetOrder added in v1.1.0

func (l *Log) SetOrder(orders ...logOrder)

func (*Log) SetOutput

func (l *Log) SetOutput(w io.Writer)

func (*Log) SetPrefix

func (l *Log) SetPrefix(prefix string)

func (*Log) SubFlag added in v1.1.0

func (l *Log) SubFlag(flag int)

func (*Log) Trace

func (l *Log) Trace(v ...interface{})

func (*Log) Tracef

func (l *Log) Tracef(format string, v ...interface{})

func (*Log) Warn

func (l *Log) Warn(v ...interface{})

func (*Log) Warnf

func (l *Log) Warnf(format string, v ...interface{})

type LogOption

type LogOption func(logger *Log)

Create Logger

func OFlag

func OFlag(flag int) LogOption

func OName

func OName(name string) LogOption

func OOrder added in v1.1.0

func OOrder(order []logOrder) LogOption

func OPrefix

func OPrefix(prefix string) LogOption

type Logger

type Logger interface {
	Fatal(...interface{})
	Panic(...interface{})
	Error(...interface{})
	Warn(...interface{})
	Info(...interface{})
	Debug(...interface{})
	Trace(...interface{})

	Fatalf(string, ...interface{})
	Panicf(string, ...interface{})
	Errorf(string, ...interface{})
	Warnf(string, ...interface{})
	Infof(string, ...interface{})
	Debugf(string, ...interface{})
	Tracef(string, ...interface{})
}

Jump to

Keyboard shortcuts

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