xlog

package module
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2023 License: MulanPSL-2.0 Imports: 11 Imported by: 0

README

xlog

介绍
  1. go 实现的 log
  2. 默认按照日进行分割,支持自定义前缀,彩色打印输出控制台,输出到 logfile

Documentation

Index

Constants

View Source
const (
	FileShort    = 1 << iota // 文件简短名, 如: test.go:11
	FileLong                 // 文件全路径, 如: /a/b/c/test.go:11
	XLogDate                 // 日期, 如: 2008-02-22
	XLogTime                 // 时间, 如: 01:23:23
	XLogTimeMill             // 毫秒级时间, 如: 01:23:23.675
	FileTimeStd  = FileShort | XLogDate | XLogTimeMill
)
View Source
const (
	LevelDebug = 1 << iota
	LevelInfo
	LevelWarn
	LevelError
	LevelPanic
	LevelFatal

	LevelDev  = LevelDebug | LevelInfo | LevelWarn | LevelError | LevelFatal | LevelPanic
	LevelProd = LevelInfo | LevelWarn | LevelError | LevelFatal | LevelPanic
)

Variables

This section is empty.

Functions

func Debug

func Debug(v ...interface{})

Debug

func Debugf

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

Debugf

func Error

func Error(v ...interface{})

Error

func Errorf

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

Errorf

func Fatal

func Fatal(v ...interface{})

Fatal

func Fatalf

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

Fatalf

func Info

func Info(v ...interface{})

Info

func Infof

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

Infof

func Panic

func Panic(v ...interface{})

Panic

func Panicf

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

Panicf

func Printf

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

Printf

func Println

func Println(v ...interface{})

Println

func Warning

func Warning(v ...interface{})

Warning

func Warningf

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

Warningf

Types

type Config

type Config struct {
	StdPrint           bool // 是否输出到控制台
	StdPrintLevelColor bool // 根据内容打印颜色, 如果要写入日志文件的话, 这里将失效
	PrintErrStack      bool // log err 时是否要打印堆栈信息
	Writer             []io.Writer
	Flags              int            // log 标记
	Level              int            // 日志级别
	CallSkip           int            // 获取调用信息需要跳过的调用层数
	Prefix             string         // 前缀
	FilePath           string         // 日志文件
	LevelPrefixes      map[int]string // 自定义前缀
}

Config logger 配置

func NewDefaultConfig

func NewDefaultConfig() *Config

NewDefaultConfig 默认配置

type XLogger

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

XLogger 默认按天进行分割

func DefaultLogger

func DefaultLogger() *XLogger

DefaultLogger

func New

func New() *XLogger

New 初始化

func (*XLogger) Debug

func (x *XLogger) Debug(v ...interface{})

Debug

func (*XLogger) Debugf

func (x *XLogger) Debugf(format string, v ...interface{})

func (*XLogger) Error

func (x *XLogger) Error(v ...interface{})

Error

func (*XLogger) Errorf

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

Errorf

func (*XLogger) Fatal

func (x *XLogger) Fatal(v ...interface{})

Fatal

func (*XLogger) Fatalf

func (x *XLogger) Fatalf(format string, v ...interface{})

Fatalf

func (*XLogger) FilePath

func (x *XLogger) FilePath(path string)

FilePath 日志文件路径

func (*XLogger) Flags

func (x *XLogger) Flags(flags int)

Flags 设置需要打印的标记

func (*XLogger) GetLevel

func (x *XLogger) GetLevel() int

GetLevel 获取配置的日志级别

func (*XLogger) GetLevelPrefix

func (x *XLogger) GetLevelPrefix(level int) string

GetLevelPrefix 获取日志前缀

func (*XLogger) Info

func (x *XLogger) Info(v ...interface{})

Info

func (*XLogger) Infof

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

Infof

func (*XLogger) Panic

func (x *XLogger) Panic(v ...interface{})

Panic

func (*XLogger) Panicf

func (x *XLogger) Panicf(format string, v ...interface{})

Panicf

func (*XLogger) Prefix

func (x *XLogger) Prefix(v string)

Prefix 日志前缀

func (*XLogger) PrintErrStack

func (x *XLogger) PrintErrStack(print bool)

PrintErrStack 是否要打印 stack

func (*XLogger) Printf

func (x *XLogger) Printf(format string, v ...interface{})

Printf

func (*XLogger) Println

func (x *XLogger) Println(v ...interface{})

Println

func (*XLogger) SetLevel

func (x *XLogger) SetLevel(level int)

SetLevel 设置日志级别

func (*XLogger) SetLevelPrefix

func (x *XLogger) SetLevelPrefix(level int, prefix string)

SetLevelPrefix 设置日志前缀

func (*XLogger) Skip added in v1.0.8

func (x *XLogger) Skip(skip int) *XLogger

Skip 设置打印调用跳过的层数

func (*XLogger) StdPrint

func (x *XLogger) StdPrint(print bool)

StdPrint 设置是否打印到控制台

func (*XLogger) StdPrintLevelColor

func (x *XLogger) StdPrintLevelColor(print bool)

StdPrintLevelColor 是否需要对日志级别标记颜色

func (*XLogger) Warning

func (x *XLogger) Warning(v ...interface{})

Warning

func (*XLogger) Warningf

func (x *XLogger) Warningf(format string, v ...interface{})

Warningf

func (*XLogger) Writer

func (x *XLogger) Writer(w ...io.Writer)

Writer 设置打印到, 设置了, 就不会打印到 文件和控制台

Directories

Path Synopsis
_example

Jump to

Keyboard shortcuts

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