Docs Go

Go documentation

GO

github.com/fintechiq/logwatcher-sdk-go — stdlib-only Go module for services, GCP-aware (detects Cloud Run and App Engine identity). Panic reporting, graceful-shutdown drain, gzip batches. Each service instance appears in the dashboard as a device.

Getting started

You need an application key. Create an account, add an app in the dashboard, and copy the key shown on its card. Every SDK call is tied to that key.

Install the SDK

go get github.com/fintechiq/logwatcher-sdk-go

Working from a monorepo checkout instead? Use a replace directive:

// go.mod
require github.com/fintechiq/logwatcher-sdk-go v0.0.0
replace github.com/fintechiq/logwatcher-sdk-go => ../path/to/client-sdks/go/logwatcher-sdk

Initialize

Initialize in main() and drain the queue on graceful shutdown:

import logwatcher "github.com/fintechiq/logwatcher-sdk-go"

func main() {
    err := logwatcher.Init(logwatcher.Config{
        AppKey: "YOUR_APP_KEY",
        APIURL: "https://fintechiq-logwatcher-19133922986.europe-west1.run.app",
    })
    // identity is detected automatically on Cloud Run (K_SERVICE/K_REVISION),
    // App Engine (GAE_SERVICE) and plain hosts (hostname)
    defer logwatcher.Close(ctx)  // drain the queue on graceful shutdown
}

Prefer instance methods? logwatcher.New(cfg) returns a *Client with the same API.

Send logs

One method per level (capitalized, Go-style), plus printf variants. Logs are queued in-process and uploaded in batches; if the network is down they are retried later.

logwatcher.D("PaymentFlow", "card inserted · reading chip")
logwatcher.I("PaymentFlow", "auth approved · code 00")
logwatcher.Wf("Network", "settle latency %.1fs — retrying", 2.1) // printf variants: Tf/Df/If/Wf/Ef/Ff
logwatcher.E("PaymentFlow", "auth declined · code 05")
logwatcher.T("Lifecycle", "request started")   // trace
logwatcher.F("Watchdog", "unrecoverable state") // fatal

For full control there is also logwatcher.Log(line, method, file, level, tag, text).

LevelMethodWire value
DebugD()0
WarningW()1
ErrorE()2
TraceT()3
InfoI()4
FatalF()5

The non-sequential wire values are part of the LogWatcher wire protocol — the SDK handles the mapping.

Panic reporting

Report panics from request handlers or workers — RecoverPanic reports the panic (with debug.Stack()), flushes, then re-panics so your normal recovery still runs:

func handler(w http.ResponseWriter, r *http.Request) {
    defer logwatcher.RecoverPanic()
    // ...
}

// or report without re-panicking:
if r := recover(); r != nil { logwatcher.ReportPanic(r) }

Issues & feedback

Report a noteworthy condition as an issue, or record an operator note. Each call returns a *url.URL deep-linking to the item in your dashboard.

url := logwatcher.SendIssue("Sync failed", "3 retries exhausted on /settle")
logwatcher.SendUserFeedback("From ops", "Nightly settle needed a manual rerun")

Device key-values

Attach searchable properties to this service instance — shard, region, canary flag:

logwatcher.SetDeviceString("service", "settlement-worker")
logwatcher.SetDeviceInteger("shard", 2)
logwatcher.SetDeviceBoolean("canary", true)
logwatcher.RemoveDeviceKey("canary")

Remote device control

On startup the SDK registers the instance and receives its remote flags. From the dashboard you can enable log collection for a single instance while the rest stays quiet — no redeploy. To force collection locally regardless of the remote flag:

logwatcher.SetForceEnabled(true)   // override the remote toggle
logwatcher.ForceSendOnce()          // flush the queue right now

Advanced options

APIWhat it does
Config fieldsAppKey, APIURL, BaseURL, DeviceName, UDID (stable instance identity), AppVersion, Build, PackageID, SDKType, MaxLocalStorageBytes, HTTPClient, Logf.
New(cfg)Instance API: returns a *Client with the same methods as the package-level functions.
Flush(ctx)Drain the queue now — returns when the server has acknowledged (or ctx expires).
Close(ctx)Stop the background flusher and drain — call on graceful shutdown (e.g. Cloud Run SIGTERM).
RecoverPanic() / ReportPanic(r)Panic reporting with and without re-panic.
Tf/Df/If/Wf/Ef/Ff(tag, format, v...)Printf-style level helpers.
SetMaximumLocalStorageSize(bytes)Cap the in-memory queue (default 5 MiB); oldest entries are dropped first.
DeviceURL() / SessionURL()Dashboard deep-links for this instance / session.

The queue is in-memory (server processes are long-lived; use Flush/Close around exits). Batches ≥1 KiB are gzip-compressed; the server accepts both gzip and raw JSON.

Ready to see your first remote log?
Create an app, copy its key, and init the SDK.
Get started