elog

package module
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2023 License: MIT Imports: 6 Imported by: 4

README

elog

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

Documentation

Index

Examples

Constants

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

Fatal > Panic > Error > Warn > Info > Debug > Trace > Discard

View Source
const (
	Fatal_ = "\x1b[0;30;45m "
	Panic_ = "\x1b[1;37;45m "
	Error_ = "\x1b[1;37;41m "
	Warn_  = "\x1b[0;30;43m "
	Info_  = "\x1b[0;30;46m "
	Debug_ = "\x1b[0;37;44m "
	Trace_ = "\x1b[0;30;42m "
)
View Source
const (
	OrderDate   logOrder = "Date"
	OrderTime   logOrder = "Time"
	OrderLevel  logOrder = "Level"
	OrderPrefix logOrder = "Prefix"
	OrderPath   logOrder = "Path"
	OrderMsg    logOrder = "Message"
)
View Source
const (
	Ldate = 1 << iota
	Ltime
	Lmicroseconds
	LUTC
	Llongfile
	Lshortfile
	Lmsgprefix
	Lmsgcolor
	Llevel
	LlevelLabelColor
	LstdFlags = Ldate | Ltime | Lshortfile | Llevel
)

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

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
	AddFlag   = std.AddFlag
	SubFlag   = std.SubFlag

	// 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
Example
var b1 bytes.Buffer
SetOutput(&b1).SetFlag(Lshortfile)
Info(`This is the default logger. It is often used for global logging.`)
SetLevel(DebugLevel)
Debug(`You can change the level of default logger by SetLevel().`)

fmt.Println(b1.String())
Output:

example_test.go:84 This is the default logger. It is often used for global logging.
example_test.go:86 You can change the level of default logger by SetLevel().

func Extend

func Extend(options ...LogOption) *Log

func New

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

func (*Log) AddFlag added in v1.1.0

func (l *Log) AddFlag(flag int) *Log

Manipulate Flag

func (*Log) Debug

func (l *Log) Debug(v ...any)

func (*Log) Debugf

func (l *Log) Debugf(format string, v ...any)

func (*Log) Error

func (l *Log) Error(v ...any)

func (*Log) Errorf

func (l *Log) Errorf(format string, v ...any)

func (*Log) Extend added in v1.1.0

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

func (*Log) Fatal

func (l *Log) Fatal(v ...any)

Method Set

func (*Log) Fatalf

func (l *Log) Fatalf(format string, v ...any)

func (*Log) Flag

func (l *Log) Flag() int

func (*Log) Info

func (l *Log) Info(v ...any)

func (*Log) Infof

func (l *Log) Infof(format string, v ...any)

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 ...any)

func (*Log) Panicf

func (l *Log) Panicf(format string, v ...any)

func (*Log) Prefix

func (l *Log) Prefix() string

func (*Log) SetFlag

func (l *Log) SetFlag(flag int) *Log

func (*Log) SetLevel

func (l *Log) SetLevel(level logLevel) *Log

func (*Log) SetName

func (l *Log) SetName(name string) *Log

func (*Log) SetOrder added in v1.1.0

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

func (*Log) SetOutput

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

func (*Log) SetPrefix

func (l *Log) SetPrefix(prefix string) *Log

func (*Log) SubFlag added in v1.1.0

func (l *Log) SubFlag(flag int) *Log

func (*Log) Trace

func (l *Log) Trace(v ...any)

func (*Log) Tracef

func (l *Log) Tracef(format string, v ...any)

func (*Log) Warn

func (l *Log) Warn(v ...any)

func (*Log) Warnf

func (l *Log) Warnf(format string, v ...any)

type LogOption

type LogOption func(logger *Log)

Create Logger Option

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 OOutput added in v1.1.4

func OOutput(w1 io.Writer, w ...io.Writer) LogOption

func OPrefix

func OPrefix(prefix string) LogOption

type Logger

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

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

Jump to

Keyboard shortcuts

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