Documentation
¶
Index ¶
- func Debug(ctx context.Context, msg string, fields ...any)
- func DebugMap(ctx context.Context, msg string, fields map[string]any)
- func Error(ctx context.Context, msg string, fields ...any)
- func ErrorMap(ctx context.Context, msg string, fields map[string]any)
- func Fatal(ctx context.Context, msg string, fields ...any)
- func FatalMap(ctx context.Context, msg string, fields map[string]any)
- func Info(ctx context.Context, msg string, fields ...any)
- func InfoMap(ctx context.Context, msg string, fields map[string]any)
- func Init(opts ...Option) error
- func SetDefault(l Logger)
- func Sync() error
- func Warn(ctx context.Context, msg string, fields ...any)
- func WarnMap(ctx context.Context, msg string, fields map[string]any)
- type FileOption
- type Format
- type Level
- type Logger
- type OTLPOption
- type Option
- func WithCaller(enabled bool) Option
- func WithDevelopment() Option
- func WithFile(path string, opts ...FileOption) Option
- func WithFormat(format Format) Option
- func WithLevel(level Level) Option
- func WithOTLP(endpoint string, opts ...OTLPOption) Option
- func WithResourceAttributes(attrs ...attribute.KeyValue) Option
- func WithStacktrace(enabled bool) Option
- func WithStdout() Option
- func WithTrace(serviceName string) Option
- type Output
- type OutputConfig
- type OutputType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type FileOption ¶
type FileOption func(*OutputConfig)
FileOption 文件选项
func WithFileMaxBackups ¶
func WithFileMaxBackups(count int) FileOption
WithFileMaxBackups 设置最大备份文件数量
type Logger ¶
type Logger interface {
// 结构化字段方式(key-value 对)
Debug(ctx context.Context, msg string, fields ...any)
Info(ctx context.Context, msg string, fields ...any)
Warn(ctx context.Context, msg string, fields ...any)
Error(ctx context.Context, msg string, fields ...any)
Fatal(ctx context.Context, msg string, fields ...any)
// Map 字段方式
DebugMap(ctx context.Context, msg string, fields map[string]any)
InfoMap(ctx context.Context, msg string, fields map[string]any)
WarnMap(ctx context.Context, msg string, fields map[string]any)
ErrorMap(ctx context.Context, msg string, fields map[string]any)
FatalMap(ctx context.Context, msg string, fields map[string]any)
// With 方法创建带预设字段的子 logger
With(fields ...any) Logger
// Sync 刷新缓冲区
Sync() error
}
Logger 日志接口
type OTLPOption ¶
type OTLPOption func(*OutputConfig)
OTLPOption OTLP 选项
func WithOTLPHeaders ¶
func WithOTLPHeaders(headers map[string]string) OTLPOption
WithOTLPHeaders 设置自定义 headers
func WithOTLPTimeout ¶
func WithOTLPTimeout(timeout time.Duration) OTLPOption
WithOTLPTimeout 设置连接超时
type Option ¶
type Option func(*options)
Option 配置选项函数
func WithOTLP ¶
func WithOTLP(endpoint string, opts ...OTLPOption) Option
WithOTLP 添加 OTLP 输出(用于 SigNoz 等)
func WithResourceAttributes ¶ added in v0.1.2
WithResourceAttributes 设置 OTLP 输出的 resource attributes
type OutputConfig ¶
type OutputConfig struct {
// File 配置
FilePath string
MaxSize int // MB
MaxAge int // days
MaxBackups int // 保留文件数量
Compress bool // 是否压缩
// OTLP 配置
Endpoint string
Insecure bool
Headers map[string]string
Timeout time.Duration
}
OutputConfig 输出配置详情
type OutputType ¶
type OutputType string
OutputType 输出类型
const ( StdoutOutput OutputType = "stdout" FileOutput OutputType = "file" OTLPOutput OutputType = "otlp" )
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
01_basic
command
|
|
|
02_file_output
command
|
|
|
03_with_trace
command
|
|
|
04_remote_signoz
command
|
|
|
05_production
command
|
Click to show internal directories.
Click to hide internal directories.