Documentation ¶
Index ¶
- func Close(names ...string)
- func Flush(names ...string)
- func IncrementAnalyze(filePath string, handle func(analyzer *Analyzer, record R)) func() (*Report, error)
- func Record(name string, data map[string]any)
- func RecordBytes(name string, data []byte)
- func Reg(name string, flusher Flusher, options ...Option)
- type Analyzer
- func (slf *Analyzer) GetValue(key string) float64
- func (slf *Analyzer) GetValueString(key string) string
- func (slf *Analyzer) Increase(key string, record R, recordKey string)
- func (slf *Analyzer) IncreaseNonRepeat(key string, record R, recordKey string, dimension ...string)
- func (slf *Analyzer) IncreaseValue(key string, value float64)
- func (slf *Analyzer) IncreaseValueNonRepeat(key string, record R, value float64, dimension ...string)
- func (slf *Analyzer) SetFormat(key string, format func(v any) any)
- func (slf *Analyzer) SetValue(key string, value float64)
- func (slf *Analyzer) SetValueIf(key string, expression bool, value float64)
- func (slf *Analyzer) SetValueIfGreaterThan(key string, value float64)
- func (slf *Analyzer) SetValueIfLessThan(key string, value float64)
- func (slf *Analyzer) SetValueString(key string, value string)
- func (slf *Analyzer) SetValueStringIf(key string, expression bool, value string)
- func (slf *Analyzer) Sub(key string) *Analyzer
- type FileFlusher
- type Flusher
- type Option
- type R
- func (slf R) Exist(key string) bool
- func (slf R) Get(key string) Result
- func (slf R) GetBool(key string) bool
- func (slf R) GetFloat64(key string) float64
- func (slf R) GetInt(key string) int
- func (slf R) GetInt64(key string) int64
- func (slf R) GetString(key string) string
- func (slf R) GetTime(layout string) time.Time
- func (slf R) String() string
- type Report
- func (slf *Report) Avg(key string) float64
- func (slf *Report) Count(key string) int64
- func (slf *Report) FilterSub(names ...string) *Report
- func (slf *Report) ReserveSub(names ...string) *Report
- func (slf *Report) ReserveSubByPrefix(prefix string) *Report
- func (slf *Report) String() string
- func (slf *Report) Sub(name string) *Report
- func (slf *Report) Sum(keys ...string) float64
- type Result
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Analyzer ¶ added in v0.1.4
type Analyzer struct {
// contains filtered or unexported fields
}
Analyzer 分析器
func (*Analyzer) GetValueString ¶ added in v0.2.9
GetValueString 获取当前记录的值
func (*Analyzer) Increase ¶ added in v0.1.4
Increase 在指定 key 现有值的基础上增加 recordKey 的值
- 当分析器已经记录过相同 key 的值时,会根据已有的值类型进行不同处理
处理方式:
- 当已有值类型为 string 时,将会使用新的值的 string 类型进行覆盖
- 当已有值类型为 float64 时,当新的值类型不为 float64 时,将会被忽略
func (*Analyzer) IncreaseNonRepeat ¶ added in v0.1.4
IncreaseNonRepeat 在指定 key 现有值的基础上增加 recordKey 的值,但是当去重维度 dimension 相同时,不会增加
func (*Analyzer) IncreaseValue ¶ added in v0.1.4
IncreaseValue 在指定 key 现有值的基础上增加 value
func (*Analyzer) IncreaseValueNonRepeat ¶ added in v0.1.4
func (slf *Analyzer) IncreaseValueNonRepeat(key string, record R, value float64, dimension ...string)
IncreaseValueNonRepeat 在指定 key 现有值的基础上增加 value,但是当去重维度 dimension 相同时,不会增加
func (*Analyzer) SetValueIf ¶ added in v0.2.9
SetValueIf 当表达式满足的时候将设置指定 key 的值为 value
func (*Analyzer) SetValueIfGreaterThan ¶ added in v0.2.9
SetValueIfGreaterThan 设置指定 key 的值,当新值大于旧值时
- 当已有值不为 float64 时,将会被忽略
func (*Analyzer) SetValueIfLessThan ¶ added in v0.2.9
SetValueIfLessThan 设置指定 key 的值,当新值小于旧值时
- 当已有值不为 float64 时,将会被忽略
func (*Analyzer) SetValueString ¶ added in v0.2.9
SetValueString 设置指定 key 的值
func (*Analyzer) SetValueStringIf ¶ added in v0.2.9
SetValueStringIf 当表达式满足的时候将设置指定 key 的值为 value
type FileFlusher ¶ added in v0.1.2
type FileFlusher struct {
// contains filtered or unexported fields
}
func NewFileFlusher ¶ added in v0.1.2
func NewFileFlusher(filePath string, layout ...string) *FileFlusher
NewFileFlusher 创建一个文件刷新器
- layout 为日志文件名的时间戳格式 (默认为 time.DateOnly)
func (*FileFlusher) Flush ¶ added in v0.1.2
func (slf *FileFlusher) Flush(records []string)
func (*FileFlusher) Info ¶ added in v0.1.2
func (slf *FileFlusher) Info() string
type Flusher ¶ added in v0.1.2
type Flusher interface { // Flush 将缓冲区的数据持久化 Flush(records []string) // Info 返回当前刷新器的信息 Info() string }
Flusher 用于刷新缓冲区的接口
type Option ¶
type Option func(logger *logger)
Option 选项
type R ¶
type R string
R 记录器所记录的一条数据
func (R) Get ¶
Get 获取指定 key 的值
- 当 key 为嵌套 key 时,使用 . 进行分割,例如:a.b.c
- 更多用法参考:https://github.com/tidwall/gjson
func (R) GetFloat64 ¶
GetFloat64 该函数为 Get(key).Float() 的简写
type Report ¶ added in v0.1.4
type Report struct { Name string // 报告名称(默认为 ROOT) Values map[string]any `json:"Values,omitempty"` Counter map[string]int64 `json:"Count,omitempty"` Subs []*Report `json:"Reports,omitempty"` // contains filtered or unexported fields }
Report 分析报告
func Analyze ¶ added in v0.1.4
Analyze 分析特定文件的记录,当发生错误时,会发生 panic
- handle 为并行执行的,需要自行处理并发安全
- 适用于外部进程对于日志文件的读取,但是需要注意的是,此时日志文件可能正在被写入,所以可能会读取到错误的数据
func AnalyzeMulti ¶ added in v0.1.5
AnalyzeMulti 与 Analyze 类似,但是可以分析多个文件
func (*Report) ReserveSub ¶ added in v0.1.4
ReserveSub 仅保留特定名称子报告
func (*Report) ReserveSubByPrefix ¶ added in v0.2.9
ReserveSubByPrefix 仅保留特定前缀的子报告