Documentation
¶
Index ¶
- Variables
- func NewJSONLogger(debug bool, w io.Writer, sampler Sampler) *zap.Logger
- func SetCrashOutput(f *os.File) error
- func SetLevel(l string)
- func SetupSlog(cfg Config) (*slog.Logger, func())
- func WithAttr(parent context.Context, attr slog.Attr) context.Context
- type Config
- func (c Config) SetDebug(debug bool) Config
- func (c Config) SetDir(dir string) Config
- func (c Config) SetLevel(level string) Config
- func (c Config) SetMaxAge(maxAge time.Duration) Config
- func (c Config) SetRotation(b int64, duration time.Duration) Config
- func (c Config) SetRotationKB(kb int64, duration time.Duration) Config
- func (c Config) SetSampler(sampler Sampler) Config
- func (c Config) SetService(id, name, version string) Config
- type Sampler
- type Slog
Constants ¶
This section is empty.
Variables ¶
View Source
var Level = zap.NewAtomicLevelAt(zap.InfoLevel)
Level 日志级别
Functions ¶
func NewJSONLogger ¶
NewJSONLogger 创建JSON日志
Types ¶
type Config ¶
type Config struct {
Dir string // 日志写入目录
ServiceID string // 服务 ID(可选)
ServiceName string // 服务名称(可选)
ServiceVersion string // 服务版本(可选)
Debug bool // 是否开启 debug,日志会同时写终端和文件
MaxAge time.Duration // 日志保留时间
RotationTime time.Duration // 日志分割时间
RotationSize int64 // 日志分割大小,单位字节
Level string // debug/info/warn/error
Sampler Sampler // 采样器,用于控制日志写入频率(可选)
}
Config ....
func NewDefaultConfig ¶
func NewDefaultConfig() Config
NewDefaultConfig 创建默认配置 默认行为 - 最大 50MB 的文件即创建新文件 - 12 小时分割一个新的日志文件 - 仅保留最近 7 天的文件
func (Config) SetRotation ¶ added in v1.4.1
SetRotation 注意单位是 b Deprecated: 建议使用 SetRotationKB
func (Config) SetRotationKB ¶ added in v1.5.1
SetRotationMB 按照 MB 分割日志文件,time 为分割时间间隔
func (Config) SetSampler ¶ added in v1.4.1
SetSampler 设置采样器,用于控制日志写入频率(可选)
func (Config) SetService ¶ added in v1.4.1
SetService 设置服务信息,可选 - 使用 id 作为服务唯一标识 - 使用 name 作为服务名称 - 使用 version 作为服务版本 id,name,version 空串时,将不记录到日志
Click to show internal directories.
Click to hide internal directories.