log

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: MulanPSL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CUTDUR_M   time.Duration = time.Minute
	CUTDUR_M5                = time.Minute * 5
	CUTDUR_M10               = time.Minute * 10
	CUTDUR_M15               = time.Minute * 15
	CUTDUR_M20               = time.Minute * 20
	CUTDUR_M30               = time.Minute * 30
	CUTDUR_H                 = time.Hour
	CUTDUR_H2                = time.Hour * 2
	CUTDUR_H3                = time.Hour * 3
	CUTDUR_H4                = time.Hour * 4
	CUTDUR_H6                = time.Hour * 6
	CUTDUR_H8                = time.Hour * 8
	CUTDUR_H12               = time.Hour * 12
	//以下遇每月1号分割
	CUTDUR_D  = time.Hour * 24 //每1天分割,取值范围[1D,2D)
	CUTDUR_D2 = CUTDUR_D * 2   //每2天分割,取值范围[2D,3D)
	CUTDUR_D3 = CUTDUR_D * 3   //每3天分割,取值范围[3D,4D)
	CUTDUR_D4 = CUTDUR_D * 4   //每4天分割,取值范围[4D,5D)
	CUTDUR_D5 = CUTDUR_D * 5   //每5天分割,取值范围[5D,6D)
	//
	CUTDUR_D6  = 1              //按周分割,从日志开始记录按周分割,取值范围[6D,7D)
	CUTDUR_D7  = CUTDUR_D * 7   //按周分割,每周一进行分割,取值范围[7D,8D)
	CUTDUR_D8  = 2              //按周分割,每周六进行分割,取值范围[8D,9D)
	CUTDUR_D9  = 3              //按周分割,每周天进行分割,取值范围[9D,10D)
	CUTDUR_D10 = CUTDUR_D * 10  //按旬分割,每月1号11号21号进行分割,取值范围[10D,15D)
	CUTDUR_D15 = CUTDUR_D * 15  //按半月分割,每月1号16号进行分割,取值范围[16D,28D)
	CUTDUR_D30 = CUTDUR_D * 30  //按月分割,取值范围[28D,90D)
	CUTDUR_Q   = CUTDUR_D30 * 3 //按季分割,取值范围[90D,180D)
	CUTDUR_Q2  = CUTDUR_Q * 2   //按半年分割,取整范围[180D,360D)
	CUTDUR_Y   = CUTDUR_Q * 4   //按年分割,取整范围[360D,+∞)
)

按时间分割日志

View Source
const (
	Lv_Fatal Levels = FATAL
	Lv_Error        = Lv_Fatal | ERROR
	Lv_Warn         = Lv_Error | WARN
	Lv_Info         = Lv_Warn | INFO
	Lv_Debug        = Lv_Info | DEBUG
)
View Source
const DefaultDatetimeLayout = "2006-01-02T15:04:05.000"
View Source
const DefaultMaxSize = 100 * 1024 * 1024 //100M
View Source
const FilenameLayout = "20060102150405"

Variables

This section is empty.

Functions

func Debug

func Debug(text string)

func Debugf

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

func Debugln

func Debugln(args ...interface{})

func Error

func Error(text string)

func Errorf

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

func Errorln

func Errorln(args ...interface{})

func Fatal

func Fatal(text string)

func Fatalf

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

func Fatalln

func Fatalln(args ...interface{})

func Info

func Info(text string)

func Infof

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

func Infoln

func Infoln(args ...interface{})

func LevelString added in v0.1.5

func LevelString(lv Level) string

func Log

func Log(lv Level, text string)

日志输出全局接口

func LogDepth

func LogDepth(calldepth int, lv Level, text string)

calldepth从0开始计算

func LogDepthf

func LogDepthf(calldepth int, lv Level, format string, args ...interface{})

func LogDepthln

func LogDepthln(calldepth int, lv Level, args ...interface{})

func Logf

func Logf(lv Level, format string, args ...interface{})

func Logln

func Logln(lv Level, args ...interface{})

func SetLevelName

func SetLevelName(f Level2Str)

func SetLevelParse

func SetLevelParse(f Str2Level)

func SetLogger

func SetLogger(logger Logger)

设置标准日志接口

func Warn

func Warn(text string)

func Warnf

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

func Warnln

func Warnln(args ...interface{})

Types

type FileCut

type FileCut func(string)

文件切换通知函数,参数是已经完成的文件名

type Filer

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

func NewFiler

func NewFiler(opts ...FilerOption) (*Filer, error)

func (*Filer) Close added in v0.1.6

func (f *Filer) Close() error

func (*Filer) Write

func (f *Filer) Write(content []byte) (int, error)

type FilerOption

type FilerOption func(*Filer)

func FWFileCut

func FWFileCut(fc FileCut) FilerOption

文件切换通知

func FileDelete

func FileDelete(h, m, s int) FilerOption

循环删除时间节点,参数未时分秒

func FileDuration

func FileDuration(d time.Duration) FilerOption

按时间分割文件

func FileExt

func FileExt(ext string) FilerOption

func FileMaxSize

func FileMaxSize(m int) FilerOption

日志文件最大字节数

func FileRoot

func FileRoot(p string) FilerOption

func FileSaveDays

func FileSaveDays(m int) FilerOption

日志最多保存时长

type Formatter

type Formatter interface {
	//calldepth 调用层数,需要展示的最顶层第0层
	//w 写入接口
	//lv 日志类型
	//后面包含日志参数
	//返回日志填充的缓存
	Sprint(calldepth int, w io.Writer, lv Level, text string)
	Sprintln(calldepth int, w io.Writer, lv Level, args ...interface{})
	Sprintf(calldepth int, w io.Writer, lv Level, format string, args ...interface{})
}

type FormatterOption

type FormatterOption func(*formatterOptions)

func FDatetimeLayout

func FDatetimeLayout(layout string) FormatterOption

func FLineFeed

func FLineFeed() FormatterOption

func FMsgprefix

func FMsgprefix(a ...interface{}) FormatterOption

func FProperties

func FProperties(p Properties) FormatterOption

type Level

type Level uint
const (
	FATAL Level = 1 << iota
	ERROR
	WARN
	INFO
	DEBUG
)
const NOLOG Level = 0

func ParseLevel added in v0.1.5

func ParseLevel(lv string) Level

func (Level) String

func (x Level) String() string

type Level2Str

type Level2Str func(Level) string

type Levels

type Levels = Level

func NewLevel

func NewLevel(ct string) Levels

func (Levels) Enable

func (x Levels) Enable(lv Level) bool

type LogOption

type LogOption func(*logger)

func LogFormatter

func LogFormatter(formatter Formatter) LogOption

func LogMustLevels added in v0.2.0

func LogMustLevels(lvs Levels) LogOption

func LogSetWriter

func LogSetWriter(writer LogWriter) LogOption

type LogWriter

type LogWriter interface {
	io.Writer
	//获取可写日志类型
	GetLevels() Levels
	//判断是否写入
	IsWrite(lv Level) bool
	//写日志
	WriteLog(lv Level, content []byte)
	//关闭
	Close() error
}

func NewConsoleWriter

func NewConsoleWriter(opts ...LogWriterOption) LogWriter

控制台输出

func NewLogWriter added in v0.2.0

func NewLogWriter(opts ...LogWriterOption) LogWriter

type LogWriterOption added in v0.1.6

type LogWriterOption func(*logWriterOptions)

func LWErrHandler added in v0.1.6

func LWErrHandler(eh WriterErrHandler) LogWriterOption

func LWLevel added in v0.1.6

func LWLevel(lv Levels) LogWriterOption

func LWStrLevel added in v0.1.6

func LWStrLevel(lv string) LogWriterOption

func LWithWriter added in v0.1.6

func LWithWriter(writer io.Writer) LogWriterOption

type Logger

type Logger interface {
	//标准接口
	Log(lv Level, text string)
	Logln(lv Level, args ...interface{})
	Logf(lv Level, format string, args ...interface{})
	//自定义calldepth,顶层从0开始计算
	LogDepth(calldepth int, lv Level, text string)
	LogDepthln(calldepth int, lv Level, args ...interface{})
	LogDepthf(calldepth int, lv Level, format string, args ...interface{})
	//关闭日志
	Shutdown()
}

日志接口定义

func GetLogger added in v0.2.0

func GetLogger() Logger

func NewLogger

func NewLogger(opts ...LogOption) Logger

type MultiWriter

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

多个输出终端

func NewMultiWriter

func NewMultiWriter(ws ...LogWriter) *MultiWriter

func (*MultiWriter) Close added in v0.2.0

func (w *MultiWriter) Close() error

func (*MultiWriter) GetLevels

func (w *MultiWriter) GetLevels() Levels

func (*MultiWriter) IsWrite

func (w *MultiWriter) IsWrite(lv Level) bool

func (*MultiWriter) Write

func (w *MultiWriter) Write(content []byte) (int, error)

func (*MultiWriter) WriteLog

func (w *MultiWriter) WriteLog(lv Level, content []byte)

type PipeWriter

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

异步输出终端

func NewPipeWriter

func NewPipeWriter(opts ...LogWriterOption) *PipeWriter

func (*PipeWriter) Close added in v0.2.0

func (w *PipeWriter) Close() error

func (*PipeWriter) GetLevels

func (w *PipeWriter) GetLevels() Levels

func (*PipeWriter) IsWrite

func (w *PipeWriter) IsWrite(lv Level) bool

func (*PipeWriter) Write

func (w *PipeWriter) Write(content []byte) (int, error)

func (*PipeWriter) WriteLog

func (w *PipeWriter) WriteLog(lv Level, content []byte)

type Properties

type Properties uint

properties

const (
	Ldatetime Properties = 1 << iota // the date in the local time zone: 2006-01-02
	LUTC                             // if Ldate or Ltime is set, use UTC rather than the local time zone
	Llevel                           // the level of the log
	Lfunc                            // full file name and line number: gitee.com/a/b.c:23
	LineFeed                         // End with newline

	LstdFlags = Ldatetime | Llevel | Lfunc // initial values for the standard logger
)

func (Properties) Enable

func (x Properties) Enable(y Properties) bool

func (*Properties) Remove

func (x *Properties) Remove(y Properties)

type Str2Level

type Str2Level func(string) Level

type TextFormatter added in v0.1.6

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

func NewTextFormatter added in v0.1.6

func NewTextFormatter(opts ...FormatterOption) *TextFormatter

func (*TextFormatter) Sprint added in v0.1.6

func (f *TextFormatter) Sprint(calldepth int, w io.Writer, lv Level, text string)

func (*TextFormatter) Sprintf added in v0.1.6

func (f *TextFormatter) Sprintf(calldepth int, w io.Writer, lv Level, format string, args ...interface{})

func (*TextFormatter) Sprintln added in v0.1.6

func (f *TextFormatter) Sprintln(calldepth int, w io.Writer, lv Level, args ...interface{})

type WriterErrHandler

type WriterErrHandler func(w LogWriter, e error, log string)

Jump to

Keyboard shortcuts

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