Documentation
¶
Index ¶
- Constants
- Variables
- func BuiltinTimeFmtCompact(buff *strings.Builder, t time.Time)
- func BuiltinTimeFmtStandard(buff *strings.Builder, t time.Time)
- func GlobalLevel() int
- func SetDefaultTargets(ts []Target)
- func SetGlobalHandler(h LoggerHandler)
- func SetGlobalHandlerConfig(cfg *HandlerConfig)
- func SetGlobalLevel(l int) int
- type Context
- type ContextAllowTar
- type ContextBase
- func (ctx *ContextBase) Clear()
- func (ctx *ContextBase) FD(key string, val float64) Context
- func (ctx *ContextBase) FI(key string, val int64) Context
- func (ctx *ContextBase) FS(key string, val string) Context
- func (ctx *ContextBase) FT(key string, val FmtField) Context
- func (ctx *ContextBase) FU(key string, val uint64) Context
- func (ctx *ContextBase) FX(key string, val uint64) Context
- func (ctx *ContextBase) Level() int
- func (ctx *ContextBase) P(msg string) Context
- func (ctx *ContextBase) PF(msg string, args ...interface{}) Context
- func (ctx *ContextBase) Pre(prefix string) Context
- func (ctx *ContextBase) SetLevel(level int)
- func (ctx *ContextBase) Tar(t Target) ContextAllowTar
- func (ctx *ContextBase) UniTar(t Target) Context
- func (ctx *ContextBase) Z()
- type ContextBaseAssembleFunc
- type ContextNil
- func (ctx *ContextNil) Clear()
- func (ctx *ContextNil) FD(key string, val float64) Context
- func (ctx *ContextNil) FI(key string, val int64) Context
- func (ctx *ContextNil) FS(key string, val string) Context
- func (ctx *ContextNil) FT(key string, val FmtField) Context
- func (ctx *ContextNil) FU(key string, val uint64) Context
- func (ctx *ContextNil) FX(key string, val uint64) Context
- func (ctx *ContextNil) Level() int
- func (ctx *ContextNil) P(msg string) Context
- func (ctx *ContextNil) PF(format string, args ...interface{}) Context
- func (ctx *ContextNil) Pre(prefix string) Context
- func (ctx *ContextNil) SetLevel(l int)
- func (ctx *ContextNil) Tar(t Target) ContextAllowTar
- func (ctx *ContextNil) UniTar(t Target) Context
- func (ctx *ContextNil) Z()
- type ContextPool
- type FFArrFloat64
- type FFArrInt64
- type FFArrString
- type FFArrUint64
- type FFMapStringFloat64
- type FFMapStringInt64
- type FFMapStringString
- type FFMapStringUint64
- type FmtField
- type FuncTimeFmt
- type Handler
- func (h *Handler) AddPrefix(key, val string)
- func (h *Handler) AddTarget(t Target)
- func (h *Handler) BindTimeFmt(f FuncTimeFmt)
- func (h *Handler) Clone() LoggerHandler
- func (h *Handler) Ctx() ContextAllowTar
- func (h *Handler) DBG() ContextAllowTar
- func (h *Handler) DelPrefix(key string)
- func (h *Handler) DelTarget(name string)
- func (h *Handler) ERR() ContextAllowTar
- func (h *Handler) FAT() ContextAllowTar
- func (h *Handler) INF() ContextAllowTar
- func (h *Handler) Level() int
- func (h *Handler) Release()
- func (h *Handler) SetLevel(l int)
- func (h *Handler) SetSeperator(sep string)
- func (h *Handler) SwitchCodeLine(b bool)
- func (h *Handler) SwitchJSONAssemble(b bool)
- func (h *Handler) TRC() ContextAllowTar
- func (h *Handler) WAR() ContextAllowTar
- type HandlerCommon
- type HandlerConfig
- type Logger
- type LoggerHandler
- type RotateConfig
- type Target
- type TargetFile
- type TargetFileRotate
- type TargetStdout
Constants ¶
const ( LvlInvalid = int(iota) //0 LvlTrace //1 LvlDebug //2 LvlInfo //3 LvlWarning //4 LvlError //5 LvlFatal //6 )
define log level
Variables ¶
var ( //BCodeLineDetail switch of detail code line string BCodeLineDetail = false )
var CtxNil = ContextAllowTar(&ContextNil{})
CtxNil this context doesnot do anything
var Stdout = &TargetStdout{}
Stdout Target to stdout
Functions ¶
func BuiltinTimeFmtCompact ¶
BuiltinTimeFmtCompact is builtin FuncTimeFmt with format "20190422160345223".
func BuiltinTimeFmtStandard ¶
BuiltinTimeFmtStandard is builtin FuncTimeFmt with format "2019-04-22 16:03:45.223".
func GlobalLevel ¶
func GlobalLevel() int
GlobalLevel get current global level. Global level is also the switch of log level check.
func SetDefaultTargets ¶
func SetDefaultTargets(ts []Target)
SetDefaultTargets set target list for default. It is used for creating logger handler.
func SetGlobalHandler ¶
func SetGlobalHandler(h LoggerHandler)
SetGlobalHandler return the global handler.
func SetGlobalHandlerConfig ¶ added in v0.2.0
func SetGlobalHandlerConfig(cfg *HandlerConfig)
SetGlobalHandlerConfig set global handler config
func SetGlobalLevel ¶
SetGlobalLevel set current global level. return the new level after set. Global level is also the switch of log level check.
Types ¶
type Context ¶ added in v0.2.0
type Context interface { //clear context content Clear() //finally output function. Z() //get log level of context. Level() int //set log level to context. just available before any assemble function. SetLevel(level int) //add a temporay prefix in current log message util Z(). Pre(prefix string) Context //formatted key-value message field. FS(key string, val string) Context //string value FI(key string, val int64) Context //integer value FU(key string, val uint64) Context //unsigned integer value FD(key string, val float64) Context //double-float value FX(key string, val uint64) Context //hex value //formatted key-value message custommed field. FT(key string, val FmtField) Context //add a message string. P(msg string) Context //add a message string with format string and args. PF(format string, args ...interface{}) Context }
Context is a status set for processing in a message outputting. Every message must output with context. context must flush outputting by function Z().
type ContextAllowTar ¶ added in v0.2.0
type ContextAllowTar interface { Context //add a target in current log message util Z(). Tar(t Target) ContextAllowTar //only use this target in current log message util Z(). UniTar(t Target) Context }
ContextAllowTar Context allow target specify
type ContextBase ¶ added in v0.2.0
type ContextBase struct { //common config info from handler Common *HandlerCommon // contains filtered or unexported fields }
ContextBase is a status set for processing in a message outputting.
func NewContextBase ¶ added in v0.2.0
func NewContextBase(c *HandlerCommon, level int) *ContextBase
NewContextBase make a new ContextBase instance
func (*ContextBase) Clear ¶ added in v0.2.0
func (ctx *ContextBase) Clear()
Clear implement Context.Clear()
func (*ContextBase) FD ¶ added in v0.2.0
func (ctx *ContextBase) FD(key string, val float64) Context
FD implement Context.FD()
func (*ContextBase) FI ¶ added in v0.2.0
func (ctx *ContextBase) FI(key string, val int64) Context
FI implement Context.FI()
func (*ContextBase) FS ¶ added in v0.2.0
func (ctx *ContextBase) FS(key string, val string) Context
FS implement Context.FS()
func (*ContextBase) FT ¶ added in v0.2.0
func (ctx *ContextBase) FT(key string, val FmtField) Context
FT implement Context.FT()
func (*ContextBase) FU ¶ added in v0.2.0
func (ctx *ContextBase) FU(key string, val uint64) Context
FU implement Context.FU()
func (*ContextBase) FX ¶ added in v0.2.0
func (ctx *ContextBase) FX(key string, val uint64) Context
FX implement Context.FX()
func (*ContextBase) Level ¶ added in v0.2.0
func (ctx *ContextBase) Level() int
Level implement Context.Level()
func (*ContextBase) P ¶ added in v0.2.0
func (ctx *ContextBase) P(msg string) Context
P implement for Context.P()
func (*ContextBase) PF ¶ added in v0.2.0
func (ctx *ContextBase) PF(msg string, args ...interface{}) Context
PF implement for Context.PF()
func (*ContextBase) Pre ¶ added in v0.2.0
func (ctx *ContextBase) Pre(prefix string) Context
Pre implement Context.Pre()
func (*ContextBase) SetLevel ¶ added in v0.2.0
func (ctx *ContextBase) SetLevel(level int)
SetLevel implement Context.SetLevel()
func (*ContextBase) Tar ¶ added in v0.2.0
func (ctx *ContextBase) Tar(t Target) ContextAllowTar
Tar implement for Context.Tar()
func (*ContextBase) UniTar ¶ added in v0.2.0
func (ctx *ContextBase) UniTar(t Target) Context
UniTar implement for Context.UniTar()
type ContextBaseAssembleFunc ¶ added in v0.2.0
type ContextBaseAssembleFunc func(*ContextBase) string
ContextBaseAssembleFunc assemble function for ContextBase implement
type ContextNil ¶ added in v0.2.0
type ContextNil struct { }
ContextNil this context doesnot do anything
func (*ContextNil) Clear ¶ added in v0.2.0
func (ctx *ContextNil) Clear()
Clear implement Context.Clear()
func (*ContextNil) FD ¶ added in v0.2.0
func (ctx *ContextNil) FD(key string, val float64) Context
FD implement Context.FD()
func (*ContextNil) FI ¶ added in v0.2.0
func (ctx *ContextNil) FI(key string, val int64) Context
FI implement Context.FI()
func (*ContextNil) FS ¶ added in v0.2.0
func (ctx *ContextNil) FS(key string, val string) Context
FS implement Context.FS()
func (*ContextNil) FT ¶ added in v0.2.0
func (ctx *ContextNil) FT(key string, val FmtField) Context
FT implement Context.FT()
func (*ContextNil) FU ¶ added in v0.2.0
func (ctx *ContextNil) FU(key string, val uint64) Context
FU implement Context.FU()
func (*ContextNil) FX ¶ added in v0.2.0
func (ctx *ContextNil) FX(key string, val uint64) Context
FX implement Context.FX()
func (*ContextNil) Level ¶ added in v0.2.0
func (ctx *ContextNil) Level() int
Level implement Context.Level()
func (*ContextNil) P ¶ added in v0.2.0
func (ctx *ContextNil) P(msg string) Context
P implement Context.P()
func (*ContextNil) PF ¶ added in v0.2.0
func (ctx *ContextNil) PF(format string, args ...interface{}) Context
PF implement Context.PF()
func (*ContextNil) Pre ¶ added in v0.2.0
func (ctx *ContextNil) Pre(prefix string) Context
Pre implement Context.Pre()
func (*ContextNil) SetLevel ¶ added in v0.2.0
func (ctx *ContextNil) SetLevel(l int)
SetLevel implement Context.SetLevel()
func (*ContextNil) Tar ¶ added in v0.2.0
func (ctx *ContextNil) Tar(t Target) ContextAllowTar
Tar implement Context.Tar()
func (*ContextNil) UniTar ¶ added in v0.2.0
func (ctx *ContextNil) UniTar(t Target) Context
UniTar implement Context.UniTar()
type ContextPool ¶ added in v0.2.0
type ContextPool struct {
// contains filtered or unexported fields
}
ContextPool pool of context instances
func NewContextPool ¶ added in v0.2.0
func NewContextPool(common *HandlerCommon, size int) *ContextPool
NewContextPool build a ContextPool instance
func (*ContextPool) Get ¶ added in v0.2.0
func (p *ContextPool) Get(level int) ContextAllowTar
Get get a instance
type FFArrFloat64 ¶ added in v0.2.0
type FFArrFloat64 []float64
FFArrFloat64 define FmtField for []float64
func (FFArrFloat64) AssembleAsJSON ¶ added in v0.2.0
func (f FFArrFloat64) AssembleAsJSON(buff *strings.Builder, com *HandlerCommon)
AssembleAsJSON implement FmtField.AssembleAsJSON()
func (FFArrFloat64) AssembleAsLineSeperator ¶ added in v0.2.0
func (f FFArrFloat64) AssembleAsLineSeperator(buff *strings.Builder, com *HandlerCommon)
AssembleAsLineSeperator implement FmtField.AssembleAsLineSeperator()
type FFArrInt64 ¶ added in v0.2.0
type FFArrInt64 []int64
FFArrInt64 define FmtField for []int64
func (FFArrInt64) AssembleAsJSON ¶ added in v0.2.0
func (f FFArrInt64) AssembleAsJSON(buff *strings.Builder, com *HandlerCommon)
AssembleAsJSON implement FmtField.AssembleAsJSON()
func (FFArrInt64) AssembleAsLineSeperator ¶ added in v0.2.0
func (f FFArrInt64) AssembleAsLineSeperator(buff *strings.Builder, com *HandlerCommon)
AssembleAsLineSeperator implement FmtField.AssembleAsLineSeperator()
type FFArrString ¶ added in v0.2.0
type FFArrString []string
FFArrString define FmtField for []string
func (FFArrString) AssembleAsJSON ¶ added in v0.2.0
func (f FFArrString) AssembleAsJSON(buff *strings.Builder, com *HandlerCommon)
AssembleAsJSON implement FmtField.AssembleAsJSON()
func (FFArrString) AssembleAsLineSeperator ¶ added in v0.2.0
func (f FFArrString) AssembleAsLineSeperator(buff *strings.Builder, com *HandlerCommon)
AssembleAsLineSeperator implement FmtField.AssembleAsLineSeperator()
type FFArrUint64 ¶ added in v0.2.0
type FFArrUint64 []uint64
FFArrUint64 define FmtField for []uint64
func (FFArrUint64) AssembleAsJSON ¶ added in v0.2.0
func (f FFArrUint64) AssembleAsJSON(buff *strings.Builder, com *HandlerCommon)
AssembleAsJSON implement FmtField.AssembleAsJSON()
func (FFArrUint64) AssembleAsLineSeperator ¶ added in v0.2.0
func (f FFArrUint64) AssembleAsLineSeperator(buff *strings.Builder, com *HandlerCommon)
AssembleAsLineSeperator implement FmtField.AssembleAsLineSeperator()
type FFMapStringFloat64 ¶ added in v0.2.0
FFMapStringFloat64 define FmtField for map[string]float64
func (FFMapStringFloat64) AssembleAsJSON ¶ added in v0.2.0
func (f FFMapStringFloat64) AssembleAsJSON(buff *strings.Builder, com *HandlerCommon)
AssembleAsJSON implement FmtField.AssembleAsJSON()
func (FFMapStringFloat64) AssembleAsLineSeperator ¶ added in v0.2.0
func (f FFMapStringFloat64) AssembleAsLineSeperator(buff *strings.Builder, com *HandlerCommon)
AssembleAsLineSeperator implement FmtField.AssembleAsLineSeperator()
type FFMapStringInt64 ¶ added in v0.2.0
FFMapStringInt64 define FmtField for map[string]int64
func (FFMapStringInt64) AssembleAsJSON ¶ added in v0.2.0
func (f FFMapStringInt64) AssembleAsJSON(buff *strings.Builder, com *HandlerCommon)
AssembleAsJSON implement FmtField.AssembleAsJSON()
func (FFMapStringInt64) AssembleAsLineSeperator ¶ added in v0.2.0
func (f FFMapStringInt64) AssembleAsLineSeperator(buff *strings.Builder, com *HandlerCommon)
AssembleAsLineSeperator implement FmtField.AssembleAsLineSeperator()
type FFMapStringString ¶ added in v0.2.0
FFMapStringString define FmtField for map[string]string
func (FFMapStringString) AssembleAsJSON ¶ added in v0.2.0
func (f FFMapStringString) AssembleAsJSON(buff *strings.Builder, com *HandlerCommon)
AssembleAsJSON implement FmtField.AssembleAsJSON()
func (FFMapStringString) AssembleAsLineSeperator ¶ added in v0.2.0
func (f FFMapStringString) AssembleAsLineSeperator(buff *strings.Builder, com *HandlerCommon)
AssembleAsLineSeperator implement FmtField.AssembleAsLineSeperator()
type FFMapStringUint64 ¶ added in v0.2.0
FFMapStringUint64 define FmtField for map[string]uint64
func (FFMapStringUint64) AssembleAsJSON ¶ added in v0.2.0
func (f FFMapStringUint64) AssembleAsJSON(buff *strings.Builder, com *HandlerCommon)
AssembleAsJSON implement FmtField.AssembleAsJSON()
func (FFMapStringUint64) AssembleAsLineSeperator ¶ added in v0.2.0
func (f FFMapStringUint64) AssembleAsLineSeperator(buff *strings.Builder, com *HandlerCommon)
AssembleAsLineSeperator implement FmtField.AssembleAsLineSeperator()
type FmtField ¶ added in v0.2.0
type FmtField interface { //assemble field content as line with seperator AssembleAsLineSeperator(*strings.Builder, *HandlerCommon) //assemble field content as json string AssembleAsJSON(*strings.Builder, *HandlerCommon) }
FmtField define abstract formatting field
type FuncTimeFmt ¶
FuncTimeFmt define declaration of time format function
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is the builtin implement for LoggerHandler.
func NewHandlerWithConfig ¶ added in v0.2.0
func NewHandlerWithConfig(cfg *HandlerConfig) *Handler
NewHandlerWithConfig make a new Handler instance with configuration.
func (*Handler) BindTimeFmt ¶
func (h *Handler) BindTimeFmt(f FuncTimeFmt)
BindTimeFmt implement for LoggerHandler.BindTimeFmt()
func (*Handler) Clone ¶
func (h *Handler) Clone() LoggerHandler
Clone implement for LoggerHandler.Clone()
func (*Handler) Ctx ¶ added in v0.2.0
func (h *Handler) Ctx() ContextAllowTar
Ctx implement for Logger.Ctx()
func (*Handler) Release ¶ added in v0.3.0
func (h *Handler) Release()
Release implement for LoggerHandler.Release()
func (*Handler) SetSeperator ¶
SetSeperator implement for LoggerHandler.SetSeperator()
func (*Handler) SwitchCodeLine ¶
SwitchCodeLine implement for LoggerHandler.SwitchCodeLine
func (*Handler) SwitchJSONAssemble ¶ added in v0.2.0
SwitchJSONAssemble implement for LoggerHandler.SwitchJSONAssemble
type HandlerCommon ¶ added in v0.2.0
type HandlerCommon struct { //seperator char between message field. Sep string //seperator char in format message field. SepFmt string //time format function bond with handler. TimeFmt FuncTimeFmt //outputting target list. Targets []Target //prefixes Prefixes [][2]string //prefix string cache PrefixStr string //switch of code line outputting BCodeLine bool //switch of JSON assemble using UseJSONAssemble bool }
HandlerCommon common config info of handler
type HandlerConfig ¶ added in v0.2.0
type HandlerConfig struct { //log level Level int `json:"level,omitempty"` //seperator char between message field Seperator string `json:"seperator,omitempty"` //seperator char in format message field FmtSeperator string `json:"fmt_seperator,omitempty"` //switch of code line outputting BCodeLine bool `json:"b_code_line,omitempty"` //switch of assemble message using JSON BUseJSONAssemble bool `json:"b_use_json_assemble,omitempty"` //size of idle context instance in handler context pool ContextPoolSize int }
HandlerConfig define config options of Handler
func GlobalHandlerConfig ¶ added in v0.2.0
func GlobalHandlerConfig() *HandlerConfig
GlobalHandlerConfig get global handler config
type Logger ¶
type Logger interface { //start logging message Ctx() ContextAllowTar //start logging message with specify log level TRC() ContextAllowTar DBG() ContextAllowTar INF() ContextAllowTar WAR() ContextAllowTar ERR() ContextAllowTar FAT() ContextAllowTar }
Logger Interface about output behaviors of log handler.
type LoggerHandler ¶
type LoggerHandler interface { //LoggerHandler is a superset of Logger. Logger //clone a new LoggerHandler instance with same configuration. //context will not be clone. Clone() LoggerHandler //bind time format function. //time format function is used to format time "now" for outputting log message. //if param f is nil, log message have no time string. BindTimeFmt(f FuncTimeFmt) //set seperator of log format. default seperator is "|". SetSeperator(sep string) //get current log level Level() int //set log level for handler. SetLevel(l int) //add a output target to handler. AddTarget(t Target) //del a output target from handler. DelTarget(name string) //add a prefix. //every prefix string will be joined to every log message. //param key is a inner identifier. only param value will be joined to message. AddPrefix(key, val string) //delete a prefix by key. DelPrefix(key string) //switch whether outputting code line in log message. SwitchCodeLine(b bool) //switch whether use json to assemble log message. SwitchJSONAssemble(b bool) //release log handler resources Release() }
LoggerHandler Interface of log handler. LoggerHandler is an abstract definition. A log handler is a object instance that can be configured with some properties. And provides interfaces to output log message.
func GlobalHandler ¶
func GlobalHandler() LoggerHandler
GlobalHandler return the global handler. It is the handler accepting static Logger function.
func NewHandler ¶
func NewHandler() LoggerHandler
NewHandler return a Handler instance as a LoggerHandler interface instance.
type RotateConfig ¶ added in v0.3.0
type RotateConfig struct { Dir string Prefix string Ext string //seconds RotateDuring int64 //bytes RotateSize int64 }
RotateConfig 滚动配置
type Target ¶
type Target interface { //name of target. Name() string //using count of target IncrUsing() //check whether target need ignore a log message. //param l is log level. IsIgnore(l int) bool //output message Put(msg string) //close target resources Close() }
Target is abstract interface of output target definition.
func GetDefaultTargets ¶
func GetDefaultTargets() []Target
GetDefaultTargets get target list from default
type TargetFile ¶
type TargetFile struct {
// contains filtered or unexported fields
}
TargetFile implement Target with normal file printing.
func MakeTargetFile ¶
func MakeTargetFile(dir string, fn string) (*TargetFile, error)
MakeTargetFile make a TargetFile instance with specific directory and file name.
func (*TargetFile) IncrUsing ¶ added in v0.3.0
func (t *TargetFile) IncrUsing()
IncrUsing implement for Target.IncrUsing()
func (*TargetFile) IsIgnore ¶
func (t *TargetFile) IsIgnore(l int) bool
IsIgnore implement for Target.IsIgnore()
func (*TargetFile) ReopenFile ¶
func (t *TargetFile) ReopenFile() error
ReopenFile open file again. used for tools like logrotate.
func (*TargetFile) SetLevels ¶
func (t *TargetFile) SetLevels(ls []int)
SetLevels set levels this target should output.
type TargetFileRotate ¶ added in v0.3.0
type TargetFileRotate struct {
// contains filtered or unexported fields
}
TargetFileRotate file target with rotation.
func MakeTargetFileRotate ¶ added in v0.3.0
func MakeTargetFileRotate(cfg *RotateConfig) (*TargetFileRotate, error)
MakeTargetFileRotate make a TargetFileRotate instance.
func (*TargetFileRotate) Close ¶ added in v0.3.0
func (t *TargetFileRotate) Close()
Close close file
func (*TargetFileRotate) IncrUsing ¶ added in v0.3.0
func (t *TargetFileRotate) IncrUsing()
IncrUsing implement for Target.IncrUsing()
func (*TargetFileRotate) IsIgnore ¶ added in v0.3.0
func (t *TargetFileRotate) IsIgnore(l int) bool
IsIgnore implement for Target.IsIgnore()
func (*TargetFileRotate) Name ¶ added in v0.3.0
func (t *TargetFileRotate) Name() string
Name implement for Target.Name()
func (*TargetFileRotate) Put ¶ added in v0.3.0
func (t *TargetFileRotate) Put(msg string)
Put implement for Target.Put()
func (*TargetFileRotate) SetLevels ¶ added in v0.3.0
func (t *TargetFileRotate) SetLevels(ls []int)
SetLevels set levels this target should output.
type TargetStdout ¶
type TargetStdout struct { }
TargetStdout implement Target with stdout printing.
func (*TargetStdout) Close ¶ added in v0.3.0
func (t *TargetStdout) Close()
Close implement for Target.Close()
func (*TargetStdout) IncrUsing ¶ added in v0.3.0
func (t *TargetStdout) IncrUsing()
IncrUsing implement for Target.IncrUsing()
func (*TargetStdout) IsIgnore ¶
func (t *TargetStdout) IsIgnore(l int) bool
IsIgnore implement for Target.IsIgnore()