xlog

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2019 License: Apache-2.0 Imports: 10 Imported by: 12

Documentation

Index

Constants

View Source
const (
	XFileLogDefaultLogID = "900000001"
	SpliterDelay         = 5
	CleanDays            = -3
)

constants of XFileLog

View Source
const (
	DebugLevel = iota
	TraceLevel
	NoticeLevel
	WarnLevel
	FatalLevel
	NoneLevel
)

log level

View Source
const (
	XConsoleLogDefaultlogID = "800000001"
)

constants of XConsoleLog

View Source
const (
	XLogDefSkipNum = 4
)

log skip num

Variables

This section is empty.

Functions

func LevelFromStr

func LevelFromStr(level string) int

LevelFromStr get log level from level string

Types

type Brush

type Brush func(string) string

Brush is pretty string

func NewBrush

func NewBrush(color string) Brush

NewBrush is the constructor of Brush

type LogInstance

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

LogInstance wraps a XLogger

type LogManager

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

LogManager is the manager that hold different kind of xlog loggers

func CreateLogManager

func CreateLogManager(name string, config map[string]string, source ...string) (*LogManager, error)

CreateLogManager create log manager from configs.

func (*LogManager) Close

func (l *LogManager) Close()

Close implements XLogger

func (*LogManager) Debug

func (l *LogManager) Debug(format string, a ...interface{}) (err error)

Debug implements XLogger

func (*LogManager) Debugx

func (l *LogManager) Debugx(logID, format string, a ...interface{}) (err error)

Debugx implements XLogger

func (*LogManager) EnableLogger

func (l *LogManager) EnableLogger(name string, enable bool) (err error)

EnableLogger enable or disable a logger

func (*LogManager) Fatal

func (l *LogManager) Fatal(format string, a ...interface{}) (err error)

Fatal implements XLogger

func (*LogManager) Fatalx

func (l *LogManager) Fatalx(logID, format string, a ...interface{}) (err error)

Fatalx implements XLogger

func (*LogManager) GetLogger

func (l *LogManager) GetLogger(name string) (logger XLogger, err error)

GetLogger get logger by name

func (*LogManager) Init

func (l *LogManager) Init(name string, config map[string]string, source ...string) (err error)

Init LogManager with config. The name can be set to "console" or "file". Please reference to XConsoleLog and XFileLog.

func (*LogManager) Notice

func (l *LogManager) Notice(format string, a ...interface{}) (err error)

Notice implements XLogger

func (*LogManager) Noticex

func (l *LogManager) Noticex(logID, format string, a ...interface{}) (err error)

Noticex implements XLogger

func (*LogManager) ReOpen

func (l *LogManager) ReOpen() (err error)

ReOpen reopen all enabled loggers

func (*LogManager) RegisterLogger

func (l *LogManager) RegisterLogger(name string, logger XLogger) (err error)

RegisterLogger register a logger

func (*LogManager) SetLevel

func (l *LogManager) SetLevel(name, level string) (err error)

SetLevel implements XLogger

func (*LogManager) SetLevelAll

func (l *LogManager) SetLevelAll(level string)

SetLevelAll set level to all loggers

func (*LogManager) Trace

func (l *LogManager) Trace(format string, a ...interface{}) (err error)

Trace implements XLogger

func (*LogManager) Tracex

func (l *LogManager) Tracex(logID, format string, a ...interface{}) (err error)

Tracex implements XLogger

func (*LogManager) UnregisterLogger

func (l *LogManager) UnregisterLogger(name string) (err error)

UnregisterLogger unregister a logger

func (*LogManager) Warn

func (l *LogManager) Warn(format string, a ...interface{}) (err error)

Warn implements XLogger

func (*LogManager) Warnx

func (l *LogManager) Warnx(logID, format string, a ...interface{}) (err error)

Warnx implements XLogger

type XConsoleLog

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

XConsoleLog is the console logger

func (*XConsoleLog) Close

func (p *XConsoleLog) Close()

Close implements XLogger 关闭日志库。注意:如果没有调用Close()关闭日志库的话,将会造成文件句柄泄露

func (*XConsoleLog) Debug

func (p *XConsoleLog) Debug(format string, a ...interface{}) error

Debug implements XLogger

func (*XConsoleLog) Debugx

func (p *XConsoleLog) Debugx(logID, format string, a ...interface{}) error

Debugx implements XLogger

func (*XConsoleLog) Fatal

func (p *XConsoleLog) Fatal(format string, a ...interface{}) error

Fatal implements XLogger

func (*XConsoleLog) Fatalx

func (p *XConsoleLog) Fatalx(logID, format string, a ...interface{}) error

Fatalx implements XLogger

func (*XConsoleLog) GetHost

func (p *XConsoleLog) GetHost() string

GetHost getter of hostname

func (*XConsoleLog) Init

func (p *XConsoleLog) Init(config map[string]string) (err error)

Init init XConsoleLog

func (*XConsoleLog) Notice

func (p *XConsoleLog) Notice(format string, a ...interface{}) error

Notice implements XLogger

func (*XConsoleLog) Noticex

func (p *XConsoleLog) Noticex(logID, format string, a ...interface{}) error

Noticex implements XLogger

func (*XConsoleLog) ReOpen

func (p *XConsoleLog) ReOpen() error

ReOpen implements XLogger

func (*XConsoleLog) SetLevel

func (p *XConsoleLog) SetLevel(level string)

SetLevel implements XLogger

func (*XConsoleLog) SetSkip

func (p *XConsoleLog) SetSkip(skip int)

SetSkip implements XLogger

func (*XConsoleLog) Trace

func (p *XConsoleLog) Trace(format string, a ...interface{}) error

Trace implements XLogger

func (*XConsoleLog) Tracex

func (p *XConsoleLog) Tracex(logID, format string, a ...interface{}) error

Tracex implements XLogger

func (*XConsoleLog) Warn

func (p *XConsoleLog) Warn(format string, a ...interface{}) error

Warn implements XLogger

func (*XConsoleLog) Warnx

func (p *XConsoleLog) Warnx(logID, format string, a ...interface{}) error

Warnx implements XLogger

type XFileLog

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

XFileLog is the file logger

func (*XFileLog) Close

func (p *XFileLog) Close()

Close implements XLogger

func (*XFileLog) Debug

func (p *XFileLog) Debug(format string, a ...interface{}) error

Debug implements XLogger

func (*XFileLog) Debugx

func (p *XFileLog) Debugx(logID, format string, a ...interface{}) error

Debugx implements XLogger

func (*XFileLog) Fatal

func (p *XFileLog) Fatal(format string, a ...interface{}) error

Fatal implements XLogger

func (*XFileLog) Fatalx

func (p *XFileLog) Fatalx(logID, format string, a ...interface{}) error

Fatalx implements XLogger

func (*XFileLog) GetHost

func (p *XFileLog) GetHost() string

GetHost getter of hostname

func (*XFileLog) Init

func (p *XFileLog) Init(config map[string]string) (err error)

Init implements XLogger

func (*XFileLog) Notice

func (p *XFileLog) Notice(format string, a ...interface{}) error

Notice implements XLogger

func (*XFileLog) Noticex

func (p *XFileLog) Noticex(logID, format string, a ...interface{}) error

Noticex implements XLogger

func (*XFileLog) ReOpen

func (p *XFileLog) ReOpen() error

ReOpen implements XLogger

func (*XFileLog) SetLevel

func (p *XFileLog) SetLevel(level string)

SetLevel implements XLogger

func (*XFileLog) SetSkip

func (p *XFileLog) SetSkip(skip int)

SetSkip implements XLogger

func (*XFileLog) Trace

func (p *XFileLog) Trace(format string, a ...interface{}) error

Trace implements XLogger

func (*XFileLog) Tracex

func (p *XFileLog) Tracex(logID, format string, a ...interface{}) error

Tracex implements XLogger

func (*XFileLog) Warn

func (p *XFileLog) Warn(format string, a ...interface{}) error

Warn implements XLogger

func (*XFileLog) Warnx

func (p *XFileLog) Warnx(logID, format string, a ...interface{}) error

Warnx implements XLogger

type XLogger

type XLogger interface {
	// init logger
	Init(config map[string]string) error

	// reopen logger
	ReOpen() error

	//设置日志级别, 级别如下: "Debug", "Trace", "Notice", "Warn", "Fatal", "None"
	SetLevel(level string)

	// set skip
	SetSkip(skip int)

	// 打印Debug日志. 当日志级别大于Debug时, 不会输出任何日志
	Debug(format string, a ...interface{}) error

	// 打印Trace日志. 当日志级别大于Trace时, 不会输出任何日志
	Trace(format string, a ...interface{}) error

	// 打印Notice日志. 当日志级别大于Notice时, 不会输出任何日志
	Notice(format string, a ...interface{}) error

	// 打印Warn日志. 当日志级别大于Warn时, 不会输出任何日志
	Warn(format string, a ...interface{}) error

	// 打印Fatal日志. 当日志级别大于Fatal时, 不会输出任何日志
	Fatal(format string, a ...interface{}) error

	// 打印Debug日志, 需要传入logID. 当日志级别大于Debug时, 不会输出任何日志
	Debugx(logID, format string, a ...interface{}) error

	// 打印Trace日志, 需要传入logID. 当日志级别大于Trace时, 不会输出任何日志
	Tracex(logID, format string, a ...interface{}) error

	// 打印Notice日志, 需要传入logID. 当日志级别大于Notice时, 不会输出任何日志
	Noticex(logID, format string, a ...interface{}) error

	// 打印Warn日志, 需要传入logID. 当日志级别大于Warn时, 不会输出任何日志
	Warnx(logID, format string, a ...interface{}) error

	// 打印Fatal日志, 需要传入logID. 当日志级别大于Fatal时, 不会输出任何日志
	Fatalx(logID, format string, a ...interface{}) error

	// 关闭日志库. 注意: 如果没有调用Close()关闭日志库的话, 将会造成文件句柄泄露
	Close()
}

XLogger declares method that log instance should implement.

func NewXConsoleLog

func NewXConsoleLog() XLogger

NewXConsoleLog is the constructor of XConsoleLog

func NewXFileLog

func NewXFileLog() XLogger

NewXFileLog is the constructor of XFileLog 生成一个日志实例,service用来标识业务的服务名。 比如:logger := xlog.NewXFileLog("gaea")

Jump to

Keyboard shortcuts

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