log

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2022 License: MulanPSL-2.0 Imports: 14 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 Level = 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 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 AFormatter

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

func NewFormatter

func NewFormatter(opts ...FormatterOption) *AFormatter

func (*AFormatter) Sprint

func (f *AFormatter) Sprint(calldepth int, buf []byte, lv Level, text string) []byte

func (*AFormatter) Sprintf

func (f *AFormatter) Sprintf(calldepth int, buf []byte, lv Level, format string, args ...interface{}) []byte

func (*AFormatter) Sprintln

func (f *AFormatter) Sprintln(calldepth int, buf []byte, lv Level, args ...interface{}) []byte

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) 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层
	//buf 外部缓存区,可以传nil
	//lv 日志类型
	//后面包含日志参数
	//返回日志填充的缓存
	Sprint(calldepth int, buf []byte, lv Level, text string) []byte
	Sprintln(calldepth int, buf []byte, lv Level, args ...interface{}) []byte
	Sprintf(calldepth int, buf []byte, lv Level, format string, args ...interface{}) []byte
}

type FormatterOption

type FormatterOption func(*AFormatter)

func FDatetimeLayout

func FDatetimeLayout(layout string) FormatterOption

func FLineFeed

func FLineFeed() FormatterOption

func FMsgprefix

func FMsgprefix(s string) 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 (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 LogSetWriter

func LogSetWriter(writer LogWriter) LogOption

type LogWriter

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

func NewConsoleWriter

func NewConsoleWriter(opts ...SingleWriterOption) LogWriter

控制台输出

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{})
}

日志接口定义

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) 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 MutexWriter

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

加锁输出

func NewMutexWriter

func NewMutexWriter(opts ...SingleWriterOption) *MutexWriter

func (*MutexWriter) GetLevels

func (w *MutexWriter) GetLevels() Levels

func (*MutexWriter) IsWrite

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

func (*MutexWriter) SetErrHandler

func (w *MutexWriter) SetErrHandler(eh WriterErrHandler)

func (*MutexWriter) SetLevels

func (w *MutexWriter) SetLevels(lvs Levels)

func (*MutexWriter) WithWriter

func (w *MutexWriter) WithWriter(writer io.Writer)

func (*MutexWriter) Write

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

func (*MutexWriter) WriteLog

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

type PipeWriter

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

异步输出终端

func NewPipeWriter

func NewPipeWriter(opts ...SingleWriterOption) *PipeWriter

func (*PipeWriter) GetLevels

func (w *PipeWriter) GetLevels() Levels

func (*PipeWriter) IsWrite

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

func (*PipeWriter) SetErrHandler

func (w *PipeWriter) SetErrHandler(eh WriterErrHandler)

func (*PipeWriter) SetLevels

func (w *PipeWriter) SetLevels(lvs Levels)

func (*PipeWriter) WithWriter

func (w *PipeWriter) WithWriter(writer io.Writer)

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
	Lhostname                        // 主机名
	Luser                            // 当前用户
	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 SingleWriter

type SingleWriter interface {
	SetLevels(lvs Levels)
	WithWriter(writer io.Writer)
	SetErrHandler(eh WriterErrHandler)
}

type SingleWriterOption

type SingleWriterOption func(SingleWriter)

func SWErrHandler

func SWErrHandler(eh WriterErrHandler) SingleWriterOption

func SWLevel

func SWLevel(lv Levels) SingleWriterOption

func SWStrLevel

func SWStrLevel(lv string) SingleWriterOption

func SWithWriter

func SWithWriter(writer io.Writer) SingleWriterOption

type Str2Level

type Str2Level func(string) Level

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