Documentation
¶
Index ¶
- func DefaultAttrFromContext(fns []func(ctx context.Context) []slog.Attr) []func(ctx context.Context) []slog.Attr
- func DefaultTimeout(timeout, fallback time.Duration) time.Duration
- func EnableAsyncErrorLogging(enabled bool)
- func Frame(pc uintptr) runtime.Frame
- func RegisterFactory(name string, factory ModuleFactory) error
- func RegisterModule(module Module) error
- func ReportAsyncError(component string, err error)
- func RunAsync(component string, task func() error)
- func SetAsyncErrorWriter(w io.Writer)
- func SetAsyncExecutorOptions(options AsyncExecutorOptions)
- func SourceLabel(f runtime.Frame) string
- func UpdateModuleConfig(name string, config Config) error
- type AsyncExecutorOptions
- type BaseModule
- func (m *BaseModule) Configure(config Config) error
- func (m *BaseModule) Enabled() bool
- func (m *BaseModule) Handler() slog.Handler
- func (m *BaseModule) Name() string
- func (m *BaseModule) Priority() int
- func (m *BaseModule) SetEnabled(enabled bool)
- func (m *BaseModule) SetHandler(handler slog.Handler)
- func (m *BaseModule) Type() ModuleType
- type Config
- type Configurable
- type Enableable
- type FormatterProvider
- type HandlerProvider
- type Healthable
- type Measurable
- type Module
- type ModuleConfig
- type ModuleFactory
- type ModuleType
- type Named
- type Registry
- func (r *Registry) Create(name string, config Config) (Module, error)
- func (r *Registry) Get(name string) (Module, bool)
- func (r *Registry) GetByType(moduleType ModuleType) []Module
- func (r *Registry) List() []Module
- func (r *Registry) ListFactories() []string
- func (r *Registry) Register(module Module) error
- func (r *Registry) RegisterFactory(name string, factory ModuleFactory) error
- func (r *Registry) Remove(name string) error
- func (r *Registry) Update(name string, config Config) error
- type Typed
- type WriteSyncer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultAttrFromContext ¶ added in v0.2.0
func DefaultAttrFromContext(fns []func(ctx context.Context) []slog.Attr) []func(ctx context.Context) []slog.Attr
DefaultAttrFromContext 规范化上下文属性提取函数列表。
func DefaultTimeout ¶ added in v0.2.0
DefaultTimeout 返回默认超时时间。
func EnableAsyncErrorLogging ¶ added in v0.2.0
func EnableAsyncErrorLogging(enabled bool)
EnableAsyncErrorLogging 开关模块异步任务错误日志输出。
func RegisterFactory ¶
func RegisterFactory(name string, factory ModuleFactory) error
RegisterFactory 全局注册工厂
func ReportAsyncError ¶ added in v0.2.0
ReportAsyncError 统一上报模块中的异步任务错误。
func SetAsyncErrorWriter ¶ added in v0.2.0
SetAsyncErrorWriter 设置模块异步任务错误输出目标;传入 nil 会恢复为 stderr。
func SetAsyncExecutorOptions ¶ added in v0.2.0
func SetAsyncExecutorOptions(options AsyncExecutorOptions)
SetAsyncExecutorOptions updates async executor workers/queue at runtime. Existing queued tasks are drained by old workers before old executor exits.
func SourceLabel ¶ added in v0.1.3
SourceLabel 将 frame 转为短路径标签。
func UpdateModuleConfig ¶ added in v0.1.2
UpdateModuleConfig 重新配置现有模块
Types ¶
type AsyncExecutorOptions ¶ added in v0.2.0
AsyncExecutorOptions controls module async task execution behavior. Values <= 0 fallback to built-in defaults.
func GetAsyncExecutorOptions ¶ added in v0.2.0
func GetAsyncExecutorOptions() AsyncExecutorOptions
GetAsyncExecutorOptions returns current async executor settings.
type BaseModule ¶
type BaseModule struct {
// contains filtered or unexported fields
}
BaseModule 基础模块实现
func NewBaseModule ¶
func NewBaseModule(name string, typ ModuleType, priority int) *BaseModule
NewBaseModule 创建基础模块
func (*BaseModule) Configure ¶
func (m *BaseModule) Configure(config Config) error
func (*BaseModule) Enabled ¶
func (m *BaseModule) Enabled() bool
func (*BaseModule) Handler ¶
func (m *BaseModule) Handler() slog.Handler
func (*BaseModule) Name ¶
func (m *BaseModule) Name() string
func (*BaseModule) Priority ¶
func (m *BaseModule) Priority() int
func (*BaseModule) SetEnabled ¶
func (m *BaseModule) SetEnabled(enabled bool)
func (*BaseModule) SetHandler ¶
func (m *BaseModule) SetHandler(handler slog.Handler)
func (*BaseModule) Type ¶
func (m *BaseModule) Type() ModuleType
type Config ¶
Config 通用配置接口
func (Config) Bind ¶ added in v0.1.1
Bind 将通用 Config 映射到强类型结构体或其他合法的 JSON 目标对象。
它通过标准库的 JSON 编解码器完成类型转换,避免在业务代码中散布显式的类型断言。 使用示例:
var opts struct {
Endpoint string `json:"endpoint"`
Timeout time.Duration `json:"timeout"`
}
if err := cfg.Bind(&opts); err != nil { ... }
任何实现了 json.Unmarshaler / encoding.TextUnmarshaler 的类型,都会被透明支持。
type Configurable ¶
Configurable 可配置接口 - 只负责配置管理。 与 Module.Configure 保持一致。
type Enableable ¶
type Enableable interface {
Enabled() bool
Enable()
Disable()
}
Enableable 可启用接口 - 只负责启用状态管理。 与 Module.Enabled 保持一致,并补充开关能力。
type FormatterProvider ¶ added in v0.1.2
type FormatterProvider interface {
FormatterFunctions() []func([]string, slog.Attr) (slog.Value, bool)
}
FormatterProvider 提供格式化函数,避免使用反射适配。
type HandlerProvider ¶
HandlerProvider 处理器提供者接口 - 只负责提供 slog.Handler。 与 Module.Handler 保持一致,并补充动态替换能力。
type Healthable ¶
Healthable 健康检查接口 - 用于诊断聚合。
type Measurable ¶
type Measurable interface {
GetMetrics() map[string]interface{}
ResetMetrics()
}
Measurable 可度量接口 - 用于诊断聚合。
type Module ¶
type Module interface {
// Name 返回模块名称
Name() string
// Type 返回模块类型
Type() ModuleType
// Configure 配置模块
Configure(config Config) error
// Handler 返回slog处理器
Handler() slog.Handler
// Priority 返回优先级,数字越小优先级越高
Priority() int
// Enabled 返回模块是否启用
Enabled() bool
}
Module 定义模块接口。
func CreateModule ¶
CreateModule 全局创建模块
type ModuleConfig ¶
type ModuleConfig struct {
Type string `json:"type"`
Name string `json:"name"`
Enabled bool `json:"enabled"`
Priority int `json:"priority"`
Config Config `json:"config"`
}
ModuleConfig 模块配置
type ModuleType ¶
type ModuleType int
ModuleType 定义模块类型
const ( TypeFormatter ModuleType = iota // 格式化器 TypeHandler // 处理器 TypeSink // 日志接收器 )
func (ModuleType) String ¶
func (mt ModuleType) String() string
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry 模块注册中心
func (*Registry) GetByType ¶
func (r *Registry) GetByType(moduleType ModuleType) []Module
GetByType 按类型获取模块列表
func (*Registry) ListFactories ¶
ListFactories 列出所有已注册的工厂名称
func (*Registry) RegisterFactory ¶
func (r *Registry) RegisterFactory(name string, factory ModuleFactory) error
RegisterFactory 注册模块工厂
type WriteSyncer ¶ added in v0.1.3
WriteSyncer 兼容 io.Writer,用于输出 handler。