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(days int) Config
- func (c Config) SetRotationTime(rotationTime time.Duration) Config
- func (c Config) SetSampler(sampler Sampler) Config
- func (c Config) SetService(id, name, version string) Config
- type FileConfig
- 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 {
ServiceID string // 服务 ID(可选)
ServiceName string // 服务名称(可选)
ServiceVersion string // 服务版本(可选)
Debug bool // 是否开启 debug,日志会同时写终端和文件
Level string // debug/info/warn/error
Sampler Sampler // 采样器,用于控制日志写入频率(可选)
FileConfig // 日志文件配置
}
func (Config) SetRotationTime ¶ added in v1.7.0
func (Config) SetSampler ¶ added in v1.4.1
SetSampler 设置采样器,用于控制日志写入频率(可选)
func (Config) SetService ¶ added in v1.4.1
SetService 设置服务信息,可选 - 使用 id 作为服务唯一标识 - 使用 name 作为服务名称 - 使用 version 作为服务版本 id,name,version 空串时,将不记录到日志
type FileConfig ¶ added in v1.7.0
Click to show internal directories.
Click to hide internal directories.