Documentation ¶
Overview ¶
Copyright 2022 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2022 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Note: 这里debug,info,stat,slow采用直接调用output的方式,而warn,error,stack采用封装调用的方式是特意设计的。 提取封装函数再调用能简化代码,但都采用封装调用的方式,很有可能条件不满足,大量的fmt.Sprint函数做无用功。
Copyright 2022 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2022 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2022 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2022 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2022 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2022 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2022 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2022 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2022 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2022 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2022 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2022 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2022 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Index ¶
- Constants
- Variables
- func CloseFiles() error
- func Debug(v string)
- func DebugDirect(v string)
- func DebugF(format string, v ...any)
- func Debugs(v ...any)
- func Disable()
- func Error(v string)
- func ErrorF(format string, v ...any)
- func ErrorFatal(v ...any)
- func ErrorFatalF(format string, v ...any)
- func Errors(v ...any)
- func Info(v string)
- func InfoDirect(v string)
- func InfoF(format string, v ...any)
- func InfoKV(v cst.KV)
- func InfoReport(kv cst.KV)
- func Infos(v ...any)
- func MustSetup(cnf *LogConfig)
- func NewLessWriter(writer io.Writer, milliseconds int) *lessWriter
- func RequestsLog(p *ReqLogEntity, flag int8)
- func ShowDebug() bool
- func ShowError() bool
- func ShowInfo() bool
- func ShowStack() bool
- func ShowStat() bool
- func ShowWarn() bool
- func Slow(v string)
- func SlowF(format string, v ...any)
- func Slows(v ...any)
- func Stack(v string)
- func StackF(format string, v ...any)
- func Stacks(v ...any)
- func Stat(v string)
- func StatF(format string, v ...any)
- func StatKV(data cst.KV)
- func Stats(v ...any)
- func Timer(v string)
- func TimerError(v string)
- func TimerF(format string, v ...any)
- func TimerKV(data cst.KV)
- func Timers(v ...any)
- func Warn(v string)
- func WarnF(format string, v ...any)
- func Warns(v ...any)
- type DailyRotateRule
- type LogConfig
- type LogStat
- type ReqLogEntity
- type RotateLogger
- type RotateRule
- type WriterCloser
Constants ¶
const ( LogLevelDebug int8 = iota // LogLevelDebug logs [everything] LogLevelInfo // LogLevelInfo logs [info, warn, error, stack] LogLevelWarn // LogLevelError includes [warn, error, stack] LogLevelError // LogLevelError includes [error, stack] LogLevelStack // LogLevelError includes [stack] )
日志级别的设定,自动显示对应级别的日志
const ( LogStyleCustom int8 = iota LogStyleSdx LogStyleSdxJson LogStyleELK LogStylePrometheus )
日志样式类型
Variables ¶
var ( LogStatSysMonitor = &LogStat{Type: 1, Fields: []string{"cpu", "mem", "gor", "gc"}} LogStatRouteReq = &LogStat{Type: 2, Fields: []string{"accept", "timeout", "drop", "qps", "ave", "max"}} LogStatCpuUsage = &LogStat{Type: 3, Fields: []string{"cpu", "total", "pass", "drop"}} LogStatBreakerOpen = &LogStat{Type: 4, Fields: []string{}} )
我们把系统收集统计信息日志的一些常量维护在这里
var CustomOutputFunc func(logLevel string, data any) string
如果采用Custom模式,必须外部指定下面这两个方法
var CustomReqLogFunc func(p *ReqLogEntity, flag int8) string
Functions ¶
func CloseFiles ¶
func CloseFiles() error
func Debug ¶
func Debug(v string)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
func DebugDirect ¶
func DebugDirect(v string)
func ErrorFatal ¶
func ErrorFatal(v ...any)
func ErrorFatalF ¶
func Info ¶
func Info(v string)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
func InfoReport ¶
func NewLessWriter ¶
func Stat ¶
func Stat(v string)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
func TimerError ¶ added in v0.4.3
func TimerError(v string)
Types ¶
type DailyRotateRule ¶
type DailyRotateRule struct {
// contains filtered or unexported fields
}
func (*DailyRotateRule) ArchiveFileName ¶
func (r *DailyRotateRule) ArchiveFileName() string
func (*DailyRotateRule) MarkRotated ¶
func (r *DailyRotateRule) MarkRotated()
func (*DailyRotateRule) NeedRotate ¶
func (r *DailyRotateRule) NeedRotate() bool
type LogConfig ¶
type LogConfig struct { AppName string `v:"def=AppName"` // 应用名称 ServerNo string `v:"def=ServerNo"` // 运行终端编号 LogMedium string `v:"def=console,enum=console|file|volume"` // 显示媒介 LogLevel string `v:"def=info,enum=debug|info|warn|error|stack"` // 记录日志的级别 LogStyle string `v:"def=sdx,enum=custom|sdx|sdx-json|elk|prometheus"` // 日志样式 LogStats bool `v:"def=true"` // 是否打印统计信息 FileFolder string `v:""` // 日志文件夹路径 FilePrefix string `v:""` // 日志文件名统一前缀(默认是AppName) FileSplit uint16 `v:"def=0,range=[0:255]"` // 日志拆分(比如32: info+stat; 64: info+timer; 160: info+stat+timer) FileKeepDays int `v:"def=7"` // 日志文件保留天数 FileGzip bool `v:"def=false"` // 是否Gzip压缩日志文件 // contains filtered or unexported fields }
type ReqLogEntity ¶
type ReqLogEntity struct { RawReq *http.Request TimeStamp time.Duration Latency time.Duration ClientIP string StatusCode int Pms cst.KV BodySize int ResData []byte CarryItems tips.CarryList }
日志参数实体
type RotateLogger ¶
type RotateLogger struct {
// contains filtered or unexported fields
}
func NewRotateLogger ¶
func NewRotateLogger(filename string, rule RotateRule, compress bool) (*RotateLogger, error)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 自动归档日志系统
func (*RotateLogger) Close ¶
func (rl *RotateLogger) Close() error
func (*RotateLogger) Writeln ¶
func (rl *RotateLogger) Writeln(str string) (err error)
每次调用都会在 str 后面自动判断并加上 \n
func (*RotateLogger) WritelnBuilder ¶
func (rl *RotateLogger) WritelnBuilder(sb *strings.Builder) (err error)
func (*RotateLogger) WritelnBytes ¶
func (rl *RotateLogger) WritelnBytes(bytes []byte) (err error)
type RotateRule ¶
type RotateRule interface { ArchiveFileName() string OutdatedFiles() []string NeedRotate() bool MarkRotated() }
func DefDailyRotateRule ¶
func DefDailyRotateRule(filename, delimiter string, days int, gzip bool) RotateRule
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
type WriterCloser ¶
type WriterCloser interface { io.Writer io.Closer Writeln(data string) (err error) WritelnBytes(data []byte) (err error) WritelnBuilder(sb *strings.Builder) (err error) }
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++