Documentation
¶
Index ¶
- Constants
- Variables
- func ResetDefaultLogger(l *Logger)
- func TimeFormatNow(format string, now time.Time) string
- func TimeFormatNowToBuffer(dst []byte, format string, now time.Time) int
- type Context
- func (c *Context) Buffer() *bytes.Buffer
- func (c *Context) D(k string, v float64) IContext
- func (c *Context) I(k string, v int64) IContext
- func (c *Context) Level() Level
- func (c *Context) Msg(msg string) IContext
- func (c *Context) Pre(p string) IContext
- func (c *Context) S(k string, v string) IContext
- func (c *Context) U(k string, v uint64) IContext
- func (c *Context) Z()
- type ContextPool
- type FakeTarget
- type Formatter
- type FormatterJson
- func (f *FormatterJson) AppendCodeLine(ctx *Context, file string, line int)
- func (f *FormatterJson) AppendFieldFloat64(ctx *Context, index int, k string, v float64)
- func (f *FormatterJson) AppendFieldInt64(ctx *Context, index int, k string, v int64)
- func (f *FormatterJson) AppendFieldString(ctx *Context, index int, k string, v string)
- func (f *FormatterJson) AppendFieldUint64(ctx *Context, index int, k string, v uint64)
- func (f *FormatterJson) AppendLevel(ctx *Context, lv Level)
- func (f *FormatterJson) AppendMessage(ctx *Context, msg string)
- func (f *FormatterJson) AppendPrefix(ctx *Context, index int, pre string)
- func (f *FormatterJson) AppendTimeBytes(ctx *Context, bs []byte)
- func (f *FormatterJson) Begin(ctx *Context)
- func (f *FormatterJson) End(ctx *Context)
- func (f *FormatterJson) FieldBegin(ctx *Context)
- func (f *FormatterJson) FieldEnd(ctx *Context)
- func (f *FormatterJson) PrefixBegin(ctx *Context)
- func (f *FormatterJson) PrefixEnd(ctx *Context)
- type FormatterSeparator
- func (f *FormatterSeparator) AppendCodeLine(ctx *Context, file string, line int)
- func (f *FormatterSeparator) AppendFieldFloat64(ctx *Context, index int, k string, v float64)
- func (f *FormatterSeparator) AppendFieldInt64(ctx *Context, index int, k string, v int64)
- func (f *FormatterSeparator) AppendFieldString(ctx *Context, index int, k string, v string)
- func (f *FormatterSeparator) AppendFieldUint64(ctx *Context, index int, k string, v uint64)
- func (f *FormatterSeparator) AppendLevel(ctx *Context, lv Level)
- func (f *FormatterSeparator) AppendMessage(ctx *Context, msg string)
- func (f *FormatterSeparator) AppendPrefix(ctx *Context, index int, pre string)
- func (f *FormatterSeparator) AppendTimeBytes(ctx *Context, bs []byte)
- func (f *FormatterSeparator) Begin(ctx *Context)
- func (f *FormatterSeparator) End(ctx *Context)
- func (f *FormatterSeparator) FieldBegin(ctx *Context)
- func (f *FormatterSeparator) FieldEnd(ctx *Context)
- func (f *FormatterSeparator) PrefixBegin(ctx *Context)
- func (f *FormatterSeparator) PrefixEnd(ctx *Context)
- type IContext
- type IContextPool
- type Level
- type Logger
- func (l *Logger) AddTarget(t Target)
- func (l *Logger) AppendPrefix(prefix string)
- func (l *Logger) AppendPrefixExclusive(prefix string, key string)
- func (l *Logger) Clone() *Logger
- func (l *Logger) DBG() IContext
- func (l *Logger) ERR() IContext
- func (l *Logger) FAT() IContext
- func (l *Logger) INF() IContext
- func (l *Logger) SwitchChecker() *SwitchChecker
- func (l *Logger) TRC() IContext
- func (l *Logger) WRN() IContext
- type LoggerConfig
- type Switch
- type SwitchChecker
- type Target
- type TargetFile
- type TargetFileConfig
- type TargetStdout
Constants ¶
View Source
const MaxSwitchModule int32 = 256
Variables ¶
View Source
var DefaultContextPool = IContextPool(newContextPool(256))
View Source
var DefaultFormatterJson = &FormatterJson{}
View Source
var DefaultFormatterSeparator = &FormatterSeparator{
Separator: "|",
KVSeparator: "=",
}
View Source
var DefaultGlobalLevel = LevelDebug
View Source
var DefaultTargetStdout = &TargetStdout{}
View Source
var GlobalSwitch = makeSwitch()
View Source
var LevelStrings = []string{
"NON",
"TRC",
"DBG",
"INF",
"WRN",
"ERR",
"FAT",
"IGN",
}
Functions ¶
func ResetDefaultLogger ¶ added in v0.2.0
func ResetDefaultLogger(l *Logger)
Types ¶
type Context ¶
func NewContext ¶
func NewContext(pool IContextPool) *Context
type ContextPool ¶
type ContextPool struct { NewCnt int64 // contains filtered or unexported fields }
func (*ContextPool) Get ¶
func (p *ContextPool) Get() *Context
func (*ContextPool) PoolSize ¶
func (p *ContextPool) PoolSize() int
func (*ContextPool) Put ¶
func (p *ContextPool) Put(ctx *Context)
type FakeTarget ¶
func (*FakeTarget) IgnoreCheck ¶
func (t *FakeTarget) IgnoreCheck(ctx *Context) bool
func (*FakeTarget) Print ¶
func (t *FakeTarget) Print(ctx *Context)
type Formatter ¶
type Formatter interface { Begin(ctx *Context) End(ctx *Context) AppendTimeBytes(ctx *Context, bs []byte) AppendLevel(ctx *Context, lv Level) PrefixBegin(ctx *Context) AppendPrefix(ctx *Context, index int, pre string) PrefixEnd(ctx *Context) FieldBegin(ctx *Context) AppendFieldInt64(ctx *Context, index int, k string, v int64) AppendFieldUint64(ctx *Context, index int, k string, v uint64) AppendFieldFloat64(ctx *Context, index int, k string, v float64) AppendFieldString(ctx *Context, index int, k string, v string) FieldEnd(ctx *Context) AppendMessage(ctx *Context, msg string) AppendCodeLine(ctx *Context, file string, line int) }
type FormatterJson ¶
type FormatterJson struct {
PrefixLikeMap bool
}
func (*FormatterJson) AppendCodeLine ¶ added in v0.2.0
func (f *FormatterJson) AppendCodeLine(ctx *Context, file string, line int)
func (*FormatterJson) AppendFieldFloat64 ¶
func (f *FormatterJson) AppendFieldFloat64(ctx *Context, index int, k string, v float64)
func (*FormatterJson) AppendFieldInt64 ¶
func (f *FormatterJson) AppendFieldInt64(ctx *Context, index int, k string, v int64)
func (*FormatterJson) AppendFieldString ¶
func (f *FormatterJson) AppendFieldString(ctx *Context, index int, k string, v string)
func (*FormatterJson) AppendFieldUint64 ¶
func (f *FormatterJson) AppendFieldUint64(ctx *Context, index int, k string, v uint64)
func (*FormatterJson) AppendLevel ¶
func (f *FormatterJson) AppendLevel(ctx *Context, lv Level)
func (*FormatterJson) AppendMessage ¶
func (f *FormatterJson) AppendMessage(ctx *Context, msg string)
func (*FormatterJson) AppendPrefix ¶
func (f *FormatterJson) AppendPrefix(ctx *Context, index int, pre string)
func (*FormatterJson) AppendTimeBytes ¶
func (f *FormatterJson) AppendTimeBytes(ctx *Context, bs []byte)
func (*FormatterJson) Begin ¶
func (f *FormatterJson) Begin(ctx *Context)
func (*FormatterJson) End ¶
func (f *FormatterJson) End(ctx *Context)
func (*FormatterJson) FieldBegin ¶
func (f *FormatterJson) FieldBegin(ctx *Context)
func (*FormatterJson) FieldEnd ¶
func (f *FormatterJson) FieldEnd(ctx *Context)
func (*FormatterJson) PrefixBegin ¶
func (f *FormatterJson) PrefixBegin(ctx *Context)
func (*FormatterJson) PrefixEnd ¶
func (f *FormatterJson) PrefixEnd(ctx *Context)
type FormatterSeparator ¶
func (*FormatterSeparator) AppendCodeLine ¶ added in v0.2.0
func (f *FormatterSeparator) AppendCodeLine(ctx *Context, file string, line int)
func (*FormatterSeparator) AppendFieldFloat64 ¶
func (f *FormatterSeparator) AppendFieldFloat64(ctx *Context, index int, k string, v float64)
func (*FormatterSeparator) AppendFieldInt64 ¶
func (f *FormatterSeparator) AppendFieldInt64(ctx *Context, index int, k string, v int64)
func (*FormatterSeparator) AppendFieldString ¶
func (f *FormatterSeparator) AppendFieldString(ctx *Context, index int, k string, v string)
func (*FormatterSeparator) AppendFieldUint64 ¶
func (f *FormatterSeparator) AppendFieldUint64(ctx *Context, index int, k string, v uint64)
func (*FormatterSeparator) AppendLevel ¶
func (f *FormatterSeparator) AppendLevel(ctx *Context, lv Level)
func (*FormatterSeparator) AppendMessage ¶
func (f *FormatterSeparator) AppendMessage(ctx *Context, msg string)
func (*FormatterSeparator) AppendPrefix ¶
func (f *FormatterSeparator) AppendPrefix(ctx *Context, index int, pre string)
func (*FormatterSeparator) AppendTimeBytes ¶
func (f *FormatterSeparator) AppendTimeBytes(ctx *Context, bs []byte)
func (*FormatterSeparator) Begin ¶
func (f *FormatterSeparator) Begin(ctx *Context)
func (*FormatterSeparator) End ¶
func (f *FormatterSeparator) End(ctx *Context)
func (*FormatterSeparator) FieldBegin ¶
func (f *FormatterSeparator) FieldBegin(ctx *Context)
func (*FormatterSeparator) FieldEnd ¶
func (f *FormatterSeparator) FieldEnd(ctx *Context)
func (*FormatterSeparator) PrefixBegin ¶
func (f *FormatterSeparator) PrefixBegin(ctx *Context)
func (*FormatterSeparator) PrefixEnd ¶
func (f *FormatterSeparator) PrefixEnd(ctx *Context)
type IContext ¶
type IContext interface { Level() Level //添加一个前缀 Pre(p string) IContext //添加一个KV对Int64 I(k string, v int64) IContext //添加一个KV对Uint64 U(k string, v uint64) IContext //添加一个KV对Float64 D(k string, v float64) IContext //添加一个KV对String S(k string, v string) IContext //语句消息, 只能有一个 Msg(msg string) IContext //结束日志拼装并输出 Z() }
用interface裁剪用户代码的调用范围
type IContextPool ¶
type Logger ¶
type Logger struct { Config LoggerConfig Level Level // contains filtered or unexported fields }
var DefaultLogger *Logger
func NewLogger ¶
func NewLogger(cfg *LoggerConfig) (*Logger, error)
func (*Logger) AppendPrefix ¶
func (*Logger) AppendPrefixExclusive ¶
func (*Logger) SwitchChecker ¶
func (l *Logger) SwitchChecker() *SwitchChecker
type LoggerConfig ¶
type LoggerConfig struct { IgnoreStdout bool TimeFormat string //使用 github.com/phuslu/fasttime 的格式化字符串 TimeFormatBufferLength int CodeLine bool CodeLineSkipCaller int CodeLineLong bool Formatter Formatter ContextPool IContextPool SwitchChecker *SwitchChecker }
func (*LoggerConfig) FixDefault ¶
func (cfg *LoggerConfig) FixDefault()
type Switch ¶
type Switch struct {
// contains filtered or unexported fields
}
bitset模型的模块日志开关 模块号请用户自行定义, 从0开始, 最大值为MaxSwitchModule-1
type SwitchChecker ¶
type SwitchChecker struct {
// contains filtered or unexported fields
}
模块日志开关检查器, 只可配置一个模块. 用于在运行时动态调整日志开关. 如果想要配置多个模块, 请分开使用多个Logger
func NewSwitchChecker ¶
func NewSwitchChecker(module int32, mask uint64) *SwitchChecker
func (*SwitchChecker) Check ¶
func (sc *SwitchChecker) Check(s *Switch) bool
func (*SwitchChecker) Clone ¶
func (sc *SwitchChecker) Clone() *SwitchChecker
type TargetFile ¶
func NewTargetFile ¶
func NewTargetFile(_cfg *TargetFileConfig) (*TargetFile, error)
func (*TargetFile) Close ¶
func (t *TargetFile) Close() error
func (*TargetFile) IgnoreCheck ¶
func (t *TargetFile) IgnoreCheck(ctx *Context) bool
func (*TargetFile) Print ¶
func (t *TargetFile) Print(ctx *Context)
type TargetFileConfig ¶
type TargetFileConfig struct { Filename string Ext string RotatePerSizeKB int64 RotatePerTimeMinute int64 // contains filtered or unexported fields }
func (*TargetFileConfig) FixDefault ¶
func (cfg *TargetFileConfig) FixDefault()
type TargetStdout ¶
type TargetStdout struct {
Level Level
}
func (*TargetStdout) IgnoreCheck ¶
func (t *TargetStdout) IgnoreCheck(ctx *Context) bool
func (*TargetStdout) Print ¶
func (t *TargetStdout) Print(ctx *Context)
Source Files
¶
Click to show internal directories.
Click to hide internal directories.