Categorygithub.com/issue9/logs/v7
modulepackage
7.6.5
Repository: https://github.com/issue9/logs.git
Documentation: pkg.go.dev

# README

logs Go PkgGoDev Go version codecov

高性能日志库

goos: darwin
goarch: amd64
pkg: github.com/imkira/go-loggers-bench
cpu: Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
BenchmarkLogsTextPositive-4   	100000000	       320.9 ns/op	      40 B/op	       2 allocs/op
BenchmarkLogsTextNegative-4   	1000000000	         9.407 ns/op	       0 B/op	       0 allocs/op
BenchmarkLogsJSONNegative-4   	1000000000	        11.42 ns/op	       0 B/op	       0 allocs/op
BenchmarkLogsJSONPositive-4   	65887180	       578.6 ns/op	      40 B/op	       2 allocs/op
import "github.com/issue9/logs/v7"

l := logs.New(logs.NewTextHandler(...))
l.DEBUG().Print("debug start...")

l.ERROR().AppendAttrs(map[string]interface{}{"k1":"v1"})
l.ERROR().Printf("带默认参数 k1=v1") // 不用 With 指定 k1,err 全都自动带上此参数

安装

go get github.com/issue9/logs/v7

版权

本项目采用 MIT 开源授权许可证,完整的授权说明可在 LICENSE 文件中找到。

# Packages

Package writers 提供了一组实现 [io.Writer] 接口的结构.

# Functions

No description provided by the author
FreeAttrLogs 回收 [AttrLogs] 如果需要频繁地生成 [AttrLogs] 且其生命周期都有固定的销毁时间点, 可以用此方法达到复用 [AttrLogs] 以达到些许性能提升。 NOTE: 此操作会让 logs 不再可用。.
No description provided by the author
MergeHandler 将多个 [Handler] 合并成一个 [Handler] 接口对象.
New 声明 Logs 对象 h 如果为 nil,则表示采用 [NewNopHandler]。.
NewBuffer 声明 [Buffer] 对象 detail 是否打印错误信息的调用堆栈;.
NewDispatchHandler 根据 [Level] 派发到不同的 [Handler] 对象 返回对象的 [Handler.New] 方法会根据其传递的 Level 参数从 d 中选择一个相应的对象返回。.
NewJSONHandler 返回将 [Record] 以 JSON 的形式写入 w 的对象 NOTE: 如果向 w 输出内容时出错,会将错误信息输出到终端作为最后的处理方式。.
No description provided by the author
NewTermHandler 返回将 [Record] 写入终端的对象 w 表示终端的接口,可以是 [os.Stderr] 或是 [os.Stdout], 如果是其它的实现者则会带控制字符一起输出; foreColors 表示各类别信息的字符颜色,背景始终是默认色,未指定的颜色会从 [defaultTermColors] 获取; NOTE: 如果向 w 输出内容时出错,将会导致 panic。.
NewTextHandler 返回将 [Record] 以普通文本的形式写入 w 的对象 NOTE: 如果向 w 输出内容时出错,会将错误信息输出到终端作为最后的处理方式。.
No description provided by the author
WithAttrs 为日志添加附加的固定字段.
WithCreated 指定日期的格式 如果 layout 为空将会禁用日期显示。.
WithDetail 错误信息的调用堆栈 如果向日志输出的是类型为 err 的信息,是否显示其调用堆栈。 NOTE: 该设置仅对 [Recorder.Error] 方法有效果, 如果将 err 传递给 [Recorder.Printf] 等方法,则遵照 [fmt.Appendf] 进行处理。.
WithLevels 指定启用的日志级别 之后也可以通过 [Logs.Enable] 进行修改。.
WithLocale 指定本地化信息 如果为 nil,那么将禁用本地化输出,如果多次调用,则以最后一次为准。 设置了此值为影响以下几个方法中实现了 [localeutil.Stringer] 的参数: - Recorder.Error 中的 error 类型参数; - Recorder.Print/Printf/Println 中的 any 类型参数; - Recorder.With 中的 any 类型参数.
WithLocation 是否显示定位信息.
WithStd 是否接管标准库中 log 和 log/slog 中的全局输出函数.

# Constants

常用的日志时间格式.
常用的日志时间格式.
常用的日志时间格式.
目前支持的日志类型.
目前支持的日志类型.
目前支持的日志类型.
目前支持的日志类型.
目前支持的日志类型.
目前支持的日志类型.
常用的日志时间格式.
常用的日志时间格式.
常用的日志时间格式.

# Structs

No description provided by the author
AttrLogs 带有固定属性的日志.
Buffer []byte 复用对象池 同时实现了 [xerrors.Printer] 接口。 [Handler] 接口的实现中可能需要用到此对象。.
Logger 日志对象.
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author
Marshaler 定义了序列化日志属性的方法 [Recorder.With] 的 val 如果实现了该接口, 那么在传递进去之后会调用该接口转换成字符串之后保存。.
No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author