A high-performance Go library for forwarding structured logs to UDP endpoints, designed for Lagoon/Kubernetes environments with built-in support for ELK stack integration.
- π High Performance: Multi-writer output (stdout + UDP) with efficient connection handling
- π Structured Logging: JSON logging using Go's native
slog
package - βοΈ Flexible Configuration: Programmatic configuration (no global flags)
- π§ ELK Stack Ready: Built-in log formatting for Logstash/Elasticsearch
- π‘οΈ Production Ready: Comprehensive error handling and graceful failures
- π Thread Safe: Serialized UDP writes ensure log integrity in concurrent environments
- π§ͺ Well Tested: 100% test coverage with benchmarks
- π¦ Zero Dependencies: Uses only Go standard library
go get github.com/salsadigitalauorg/go-lagoon-log-forwarder@latest
package main
import (
"log/slog"
"github.com/salsadigitalauorg/go-lagoon-log-forwarder"
)
func main() {
// Create configuration with defaults
cfg := logger.NewConfig()
cfg.LogType = "my-app" // Required: must match k8s namespace
cfg.LogHost = "logstash.example.com"
// Initialize logger
if err := logger.Initialize(cfg); err != nil {
panic(err)
}
// Use structured logging
slog.Info("Application started",
"version", "1.0.0",
"environment", "production",
)
slog.Error("Database connection failed",
"error", err,
"database", "postgres",
"retry_count", 3,
)
}
cfg := logger.NewConfig()
cfg.LogType = "my-microservice"
cfg.LogHost = "logs.k8s.cluster"
cfg.LogPort = 5140
cfg.ApplicationName = "user-service"
cfg.LogChannel = "ProductionLogs"
cfg.AddSource = true // Include source file/line info
if err := logger.Initialize(cfg); err != nil {
log.Fatalf("Failed to initialize logger: %v", err)
}
Field | Type | Default | Description |
---|---|---|---|
LogType |
string |
required | Log type (must match k8s namespace) |
LogHost |
string |
"" |
UDP host for log forwarding |
LogPort |
int |
5140 |
UDP port number |
ApplicationName |
string |
"" |
Application identifier |
LogChannel |
string |
"LagoonLogs" |
Channel name for log routing |
AddSource |
bool |
true |
Include source file/line information |
MessageVersion |
int |
1 |
Log message format version |
The logger produces structured JSON logs compatible with ELK stack:
{
"time": "2024-01-15T10:30:00Z",
"level": "INFO",
"message": "User authenticated",
"@version": 3,
"@timestamp": "2024-01-15T10:30:00Z",
"application": "user-service",
"channel": "LagoonLogs",
"host": "pod-abc123",
"type": "production",
"user_id": 12345,
"method": "POST"
}
msg
βmessage
time
β@timestamp
timestampOverride
β@timestamp
βββββββββββββββββββ ββββββββββββββββ βββββββββββββββββββ
β Application β β Logger β β Multi-Writer β
β βββββΆβ βββββΆβ β
β slog.Info() β β Transform β β ββββββββββββββββ
β slog.Error() β β Fields β β β Stdout ββ
βββββββββββββββββββ ββββββββββββββββ β ββββββββββββββββ
β ββββββββββββββββ
β β UDP Socket ββ
β β (Logstash) ββ
β ββββββββββββββββ
βββββββββββββββββββ
Run the comprehensive test suite:
# Run all tests
go test -v ./...
# Run tests with coverage
go test -v -race -coverprofile=coverage.out ./...
# View coverage report
go tool cover -html=coverage.out
# Run benchmarks
go test -bench=. -benchmem ./...
- Go 1.21 or later
- Git
git clone https://github.com/salsadigitalauorg/go-lagoon-log-forwarder.git
cd go-lagoon-log-forwarder
# Install dependencies
go mod download
# Run tests
go test -v ./...
# Run linter (requires golangci-lint)
golangci-lint run
This project maintains high code quality standards:
- 100% Test Coverage: All code paths tested
- Comprehensive Linting: 30+ linters via golangci-lint
- Security Scanning: Gosec security analysis
- Performance Testing: Benchmark tests included
- Multi-Version Support: Tested on Go 1.21-1.24
This project uses automated CI/CD with:
- Pull Request Testing: Comprehensive checks on all PRs
- Automatic Versioning: Semantic versioning based on conventional commits
- Automated Releases: GitHub releases with auto-generated changelogs
- Cross-Platform Testing: Linux, macOS, Windows compatibility
Use Conventional Commits for automatic versioning:
feat: add custom log formatter support # Minor version bump
fix: resolve UDP connection memory leak # Patch version bump
feat!: change Initialize function signature # Major version bump
Benchmark results on typical hardware:
BenchmarkNewConfig-10 1000000000 0.23 ns/op 0 B/op 0 allocs/op
BenchmarkConfig-10 2441269 475.40 ns/op 48 B/op 1 allocs/op
BenchmarkDefaultAttrs-10 50000000 28.50 ns/op 24 B/op 1 allocs/op
BenchmarkReplaceAttr-10 100000000 12.30 ns/op 0 B/op 0 allocs/op
We welcome contributions! Please see CONTRIBUTING.md for:
- Development workflow
- Commit message conventions
- Code quality standards
- Testing requirements
This project is licensed under the MIT License - see the LICENSE file for details.
This project uses Semantic Versioning:
- Major: Breaking changes
- Minor: New features (backward compatible)
- Patch: Bug fixes and improvements
Releases are automated based on conventional commit messages.
- π Bug Reports: GitHub Issues
- π‘ Feature Requests: GitHub Issues
- β Questions: GitHub Discussions
Built with β€οΈ by the Salsa Digital team for Lagoon & Kubernetes deployments