Go SDK
Send structured logs from Go services with the official Logstack Go SDK.
Go SDK
The official Go client for Logstack. Batch shipping, context-aware methods, optional
stdlib log capture, and graceful shutdown.
| Module | github.com/mosesedem/logstack/packages/logstack-go-sdk |
| Version | v1.0.3 |
| Default API | https://api.logstack.tech |
| Ingest path | POST {APIURL}/v1/logs |
Installation
The module lives in a monorepo subdirectory. Tags are
packages/logstack-go-sdk/vX.Y.Z (not a root-module tag).
Quick start
Configuration
| Field | Default | Description |
|---|---|---|
APIKey | — | Project ingest key (ls_live_…) |
APIURL | https://api.logstack.tech | API host (no /v1 required) |
Environment | production | Environment label on the batch |
BatchSize | 100 | Max buffered entries before flush |
FlushInterval | 5s | Background flush interval |
CaptureStdLog | true | Auto-forward log.Print* / log.Printf |
OnError | nil | Flush failure callback |
Self-hosted:
Logging API
All methods take context.Context and optional metadata:
| Level | Method | Notes |
|---|---|---|
debug | Debug | Verbose diagnostics |
info | Info | Normal operations |
warn | Warn | Recoverable issues |
error | Error | Failures |
critical | Critical | Severe failures |
fatal | Fatal | Logs then flushes |
Explicit SDK calls use source: "go-sdk". Auto-captured stdlib lines use source: "go-log".
Stdlib log capture
With CaptureStdLog enabled (default), the SDK redirects log.SetOutput to a
passthrough writer:
- Original destination (usually stderr) is preserved
- Each line is shipped as an info log with
source: "go-log" - Re-entrancy is guarded (safe if
OnErroritself logs) Close()restores the previous writer
Flush and shutdown
Close() is idempotent (safe to call more than once).
HTTP service example
Version
Troubleshooting
| Symptom | Check |
|---|---|
| No logs in dashboard | Valid APIKey, network to API host, OnError callback |
client is closed | Logging after Close() — keep the client open for the process lifetime |
Double /v1 | Pass host only (https://api…); SDK normalizes trailing /v1 |
| Stdlib logs missing | Ensure CaptureStdLog is not Bool(false) |