Go SDK
The Go SDK (github.com/scailabs/scailog-go) is the Go emit side of ScaiLog:
scailog.New plus scailog.PI give you GDPR-native structured logging that
ships entries over a Unix socket to the local scailog-agent. It is stdlib-only
(zero external dependencies) and wire-compatible with the Python, TypeScript, and
.NET SDKs — a Go-emitted entry is encrypted at ingest and decrypts correctly
through DSAR.
Install#
1 | |
Emit a log entry#
Construct a logger with scailog.New, then call a level method. Each level takes
a context.Context, a call_site_id, a constant message, a field map
(scailog.F), and any number of per-call options. Wrap personal-information
values in scailog.PI:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
Each level method returns the entry's ULID eventID (or "" if the entry was
rejected by a contract check — see below). Plain fields (method) are stored in
cleartext and must stay PI-free; scailog.PI fields are encrypted at ingest and
never enter the plaintext full-text index. When a call has no fields, pass nil.
Log levels#
Six methods with the same signature
Level(ctx, site, msg string, fields F, opts ...EmitOption) string:
1 2 3 4 5 6 | |
Contract rules#
The SDK enforces the shared ScaiLog contract before an entry leaves the process.
On a violation the entry is rejected: the method returns "" and a PII-free
diagnostic (the error code, service, and offending detail — never a field value)
is written to stderr, so the offending PII is never emitted.
site(call_site_id) must match^[A-Z0-9]+(-[A-Z0-9]+){2,}$; theAUTO-/SCAILOG-prefixes are reserved. An empty site auto-derives anAUTO-<hash>id (wire-identical to the other SDKs) rather than being dropped.scailog.PI(value, type)marks a field as personal information; markers attach to fields only, never the message.- A PI-marked field requires a subject (
SUBJECT_REQUIRED). - Reserved field names (
event_id,msg, …) are rejected the same way.
Context propagation#
Subject, trace id, and request id ride on the context.Context and are used as
defaults when a call doesn't pass them explicitly:
1 2 3 | |
The helpers are scailog.WithSubject, scailog.WithTraceID, and
scailog.WithRequestID. Explicit per-call options (scailog.Subject(...),
scailog.TraceID(...), scailog.RequestID(...)) override the context.
Configuration#
scailog.Options{Tenant, Service, Environment, SocketPath, QueueSize} configures
the logger. Environment defaults to prod, SocketPath defaults to
$SCAILOG_SOCKET or /run/scailog/agent.sock, and QueueSize defaults to
10,000.
Entries are queued and sent by a background sender as NDJSON over the socket. If
the queue is full or the socket is unavailable, the entry is written to stderr in
the same NDJSON shape (with PI values redacted) rather than being silently
dropped. Call log.Flush(timeout) before a short-lived process exits, and
log.Close() to shut down the background sender.