Documentation
¶
Index ¶
- func NewFileWriter(cfg FileConfig) io.Writer
- type Config
- func (c Config) Validate() error
- func (c Config) WithFile(path string) Config
- func (c Config) WithLevel(level string) Config
- func (c Config) WithMetrics(endpoint string) Config
- func (c Config) WithOTEL(endpoint string) Config
- func (c Config) WithService(name string) Config
- func (c Config) WithTracing(endpoint string) Config
- type ConsoleConfig
- type FileConfig
- type MetricsConfig
- type OTELConfig
- type TracingConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewFileWriter ¶
func NewFileWriter(cfg FileConfig) io.Writer
NewFileWriter creates a log file writer with rotation.
Types ¶
type Config ¶
type Config struct {
// Level sets the minimum log level: debug, info, warn, error.
// Default: "info"
Level string `yaml:"level" json:"level" env:"LOG_LEVEL"`
// Development enables development mode with:
// - Pretty console output by default
// - Caller information in logs
// - Stack traces on error/fatal
Development bool `yaml:"development" json:"development" env:"LOG_DEVELOPMENT"`
// ServiceName identifies this service in logs and OTEL.
// Default: "unknown"
ServiceName string `yaml:"service_name" json:"service_name" env:"SERVICE_NAME"`
// Version is the application version, included in logs.
Version string `yaml:"version" json:"version" env:"SERVICE_VERSION"`
// Console output configuration.
Console ConsoleConfig `yaml:"console" json:"console"`
// File output configuration (with rotation).
File FileConfig `yaml:"file" json:"file"`
// OTEL (OpenTelemetry) exporter configuration for logs.
OTEL OTELConfig `yaml:"otel" json:"otel"`
// Tracing configuration for distributed tracing.
Tracing TracingConfig `yaml:"tracing" json:"tracing"`
// Metrics configuration for OpenTelemetry metrics.
Metrics MetricsConfig `yaml:"metrics" json:"metrics"`
}
Config holds the complete logger configuration.
func Default ¶
func Default() Config
Default returns a Config with sensible production defaults. All telemetry backends (OTEL, Tracing, Metrics) are disabled by default. When enabled, they inherit endpoint/auth from OTEL config automatically.
func Development ¶
func Development() Config
Development returns a Config optimized for development.
- Debug level logging with pretty console output.
- Tracing pre-configured with "always" sampling (but disabled by default).
- Metrics pre-configured with 5s push interval (but disabled by default).
To enable observability, you must explicitly set:
cfg.OTEL.Enabled = true // For remote log export cfg.OTEL.Endpoint = "localhost:4317" cfg.OTEL.Insecure = true // For local dev cfg.Tracing.Enabled = true // For distributed tracing cfg.Metrics.Enabled = true // For metrics export
func (Config) Validate ¶
Validate checks the configuration for invalid values. Returns nil if valid, or an error describing all validation failures.
func (Config) WithMetrics ¶ added in v0.3.0
WithMetrics returns a copy of the config with metrics enabled.
func (Config) WithService ¶
WithService returns a copy of the config with the specified service name.
func (Config) WithTracing ¶
WithTracing returns a copy of the config with tracing enabled.
type ConsoleConfig ¶
type ConsoleConfig struct {
// Enabled controls whether console output is active.
// Default: true
Enabled bool `yaml:"enabled" json:"enabled"`
// Format: "json" for structured JSON, "pretty" for human-readable.
// Default: "json" (production), "pretty" (development)
Format string `yaml:"format" json:"format"`
// Color enables ANSI colors in pretty format.
// Default: true
Color bool `yaml:"color" json:"color"`
// ErrorsToStderr sends warn/error/fatal to stderr, others to stdout.
// Default: true
ErrorsToStderr bool `yaml:"errors_to_stderr" json:"errors_to_stderr"`
}
ConsoleConfig configures console (stdout/stderr) output.
type FileConfig ¶
type FileConfig struct {
// Enabled controls whether file output is active.
// Default: false
Enabled bool `yaml:"enabled" json:"enabled"`
// Path is the log file path.
// Example: "/var/log/app/app.log"
Path string `yaml:"path" json:"path"`
// MaxSizeMB is the maximum size in MB before rotation.
// Default: 100
MaxSizeMB int `yaml:"max_size_mb" json:"max_size_mb"`
// MaxAgeDays is the maximum age in days to retain old logs.
// Default: 7
MaxAgeDays int `yaml:"max_age_days" json:"max_age_days"`
// MaxBackups is the maximum number of old log files to keep.
// Default: 5
MaxBackups int `yaml:"max_backups" json:"max_backups"`
// Compress enables gzip compression of rotated log files.
// Default: true
Compress bool `yaml:"compress" json:"compress"`
}
FileConfig configures file output with rotation.
type MetricsConfig ¶ added in v0.3.0
type MetricsConfig struct {
// Enabled controls whether metrics export is active.
Enabled bool `yaml:"enabled" json:"enabled"`
// Protocol: "grpc" or "http".
Protocol string `yaml:"protocol" json:"protocol"`
// Endpoint is the OTEL collector endpoint for metrics.
// Falls back to OTEL.Endpoint if not set.
Endpoint string `yaml:"endpoint" json:"endpoint"`
// Insecure disables TLS.
Insecure bool `yaml:"insecure" json:"insecure"`
// Username for Basic Authentication (optional).
Username string `yaml:"username" json:"username" env:"METRICS_USERNAME"`
// Password for Basic Authentication (optional).
Password string `yaml:"password" json:"password" env:"METRICS_PASSWORD"`
// Headers for authentication.
Headers map[string]string `yaml:"headers" json:"headers"`
// Timeout for export.
Timeout time.Duration `yaml:"timeout" json:"timeout"`
// Interval is the push interval for metrics.
// Default: 15s
Interval time.Duration `yaml:"interval" json:"interval"`
// Temporality preference: "cumulative" (default) or "delta".
// Prometheus prefers Cumulative.
Temporality string `yaml:"temporality" json:"temporality"`
// Attributes for metrics resource.
Attributes map[string]string `yaml:"attributes" json:"attributes"`
}
MetricsConfig configures OpenTelemetry metrics export.
type OTELConfig ¶
type OTELConfig struct {
// Enabled controls whether OTEL export is active.
// Default: false
Enabled bool `yaml:"enabled" json:"enabled"`
// Protocol: "grpc" or "http". gRPC is recommended for performance.
// Default: "grpc"
Protocol string `yaml:"protocol" json:"protocol"`
// Endpoint is the OTEL collector endpoint.
// Examples: "localhost:4317" (gRPC), "localhost:4318/v1/logs" (HTTP)
Endpoint string `yaml:"endpoint" json:"endpoint"`
// Insecure disables TLS for the connection.
// Default: false
Insecure bool `yaml:"insecure" json:"insecure"`
// Username for Basic Authentication (optional).
Username string `yaml:"username" json:"username" env:"OTEL_USERNAME"`
// Password for Basic Authentication (optional).
Password string `yaml:"password" json:"password" env:"OTEL_PASSWORD"`
// Headers are additional headers to send (e.g., auth tokens).
Headers map[string]string `yaml:"headers" json:"headers"`
// Timeout is the export timeout.
// Default: 10s
Timeout time.Duration `yaml:"timeout" json:"timeout"`
// BatchSize is the number of logs per export batch.
// Default: 512
BatchSize int `yaml:"batch_size" json:"batch_size"`
// ExportInterval is how often to export batched logs.
// Default: 5s
ExportInterval time.Duration `yaml:"export_interval" json:"export_interval"`
// Attributes are additional resource attributes for OTEL.
// Example: {"environment": "production", "chain": "solana"}
Attributes map[string]string `yaml:"attributes" json:"attributes"`
}
OTELConfig configures OpenTelemetry log export.
type TracingConfig ¶
type TracingConfig struct {
// Enabled controls whether tracing is active.
Enabled bool `yaml:"enabled" json:"enabled"`
// Protocol: "grpc" or "http".
Protocol string `yaml:"protocol" json:"protocol"`
// Endpoint is the OTEL collector endpoint for traces.
// Falls back to OTEL.Endpoint if not set.
Endpoint string `yaml:"endpoint" json:"endpoint"`
// Insecure disables TLS.
Insecure bool `yaml:"insecure" json:"insecure"`
// Username for Basic Authentication (optional).
Username string `yaml:"username" json:"username" env:"TRACING_USERNAME"`
// Password for Basic Authentication (optional).
Password string `yaml:"password" json:"password" env:"TRACING_PASSWORD"`
// Headers for authentication.
Headers map[string]string `yaml:"headers" json:"headers"`
// Timeout for export.
Timeout time.Duration `yaml:"timeout" json:"timeout"`
// BatchSize for span export.
BatchSize int `yaml:"batch_size" json:"batch_size"`
// ExportInterval for batch export.
ExportInterval time.Duration `yaml:"export_interval" json:"export_interval"`
// Sampler configuration: "always", "never", or "ratio:0.5"
Sampler string `yaml:"sampler" json:"sampler"`
// Propagators: ["tracecontext", "baggage"]
Propagators []string `yaml:"propagators" json:"propagators"`
// Attributes for tracing.
Attributes map[string]string `yaml:"attributes" json:"attributes"`
}
TracingConfig configures distributed tracing.