config

package
v0.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 26, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

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"`
}

Config holds the complete logger configuration.

func Default

func Default() Config

Default returns a Config with sensible production defaults.

func Development

func Development() Config

Development returns a Config optimized for development.

func (Config) Validate

func (c Config) Validate() error

Validate checks the configuration for invalid values. Returns nil if valid, or an error describing all validation failures.

func (Config) WithFile

func (c Config) WithFile(path string) Config

WithFile returns a copy of the config with file logging enabled.

func (Config) WithLevel

func (c Config) WithLevel(level string) Config

WithLevel returns a copy of the config with the specified level.

func (Config) WithOTEL

func (c Config) WithOTEL(endpoint string) Config

WithOTEL returns a copy of the config with OTEL enabled.

func (Config) WithService

func (c Config) WithService(name string) Config

WithService returns a copy of the config with the specified service name.

func (Config) WithTracing

func (c Config) WithTracing(endpoint string) Config

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 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"`

	// Endpoint is the OTEL collector endpoint for traces.
	// Falls back to OTEL.Endpoint if not set.
	Endpoint string `yaml:"endpoint" json:"endpoint"`

	// Protocol: "grpc" or "http".
	Protocol string `yaml:"protocol" json:"protocol"`

	// Insecure disables TLS.
	Insecure bool `yaml:"insecure" json:"insecure"`

	// Sampler configuration: "always", "never", or "ratio:0.5"
	Sampler string `yaml:"sampler" json:"sampler"`

	// Propagators: ["tracecontext", "baggage"]
	Propagators []string `yaml:"propagators" json:"propagators"`

	// 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"`

	// Timeout for export.
	Timeout time.Duration `yaml:"timeout" json:"timeout"`

	// Headers for authentication.
	Headers map[string]string `yaml:"headers" json:"headers"`

	// Attributes for tracing.
	Attributes map[string]string `yaml:"attributes" json:"attributes"`
}

TracingConfig configures distributed tracing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL