How to Integrate Go Logging with ELK, Datadog, or Grafana Loki

Use third-party libraries like zap to output JSON logs from Go, then configure an agent to forward them to ELK, Datadog, or Loki.

Go does not natively integrate with ELK, Datadog, or Grafana Loki; you must use third-party logging libraries to format and ship logs. Install a structured logger like zap and configure it to output JSON, then use a sidecar or agent to forward logs to your target system.

import (
	"go.uber.org/zap"
	"go.uber.org/zap/zapcore"
)

func init() {
	encoder := zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig())
	core := zapcore.NewCore(encoder, zapcore.AddSync(os.Stdout), zapcore.InfoLevel)
	log := zap.New(core)
	log.Info("Hello, world!")
}