hello@logkit.io · Status · GitHub
Quickstart Guide

LogKit SDK for Go
Structured logs. Clear thinking.

Get up and running with the LogKit Go SDK in under five minutes. Install, configure, and emit your first structured log event.

main.go
import (
  "fmt"
  "github.com/logkit/sdk-go"
)

func main() {
  log := logkit.New(
    logkit.WithAPIKey("your-api-key-here"),
    logkit.WithService("api-gateway"),
)

  log.Info("service.started",
    "version", "v1.0.2",
    "port", 8080,
)
}
Prerequisites

Before you begin

Ensure you have a stable Go environment installed. The SDK is compatible with Go 1.18 and later.

Go Installation

Install the latest version of Go from go.dev/dl.

go version go1.21.0 linux/amd64

LogKit Account

Create a free account at app.logkit.io to generate your unique API key.

Step 1: Install the SDK

Use the standard Go module command to pull the latest stable release.

Terminal
go get github.com/logkit/sdk-go

Step 2: Initialize the Client

Import the package and create a new client instance using your API key. This connects your Go application to the LogKit platform.

main.go
import (
  "github.com/logkit/sdk-go"
)

// Initialise the logger once, typically in main()
func main() {
  log := logkit.New(
    logkit.WithAPIKey("your-api-key-here"),
    logkit.WithService("api-gateway"),
    logkit.WithEnv("production"),
)
}

Step 3: Emit Your First Log

LogKit uses a fluent API to emit structured events. Unlike standard libraries that log strings, LogKit logs typed JSON objects.

main.go
func main() {
  log := logkit.New(logkit.WithAPIKey("your-api-key-here"))

  // Emit a generic informational event
  log.Info("user.created",
    "user_id", 101,
    "email", "sarah@example.com",
    "signup_source", "landing_page",
)

  fmt.Println("Log event sent!")
}

Step 4: Verify in Console

Run your program (`go run main.go`). Navigate to your LogKit dashboard to see the live event.

You should see a new entry in the "Live" view of your LogKit console. The event will include the user_id, email, and signup_source fields as searchable attributes.

Structured logging allows you to filter this event later by typing user_id: 101 directly into the search bar.

LogKit console showing the user.created event with structured fields

Advanced Configuration

Customize your logging behavior for different environments and data formats.

Log Levels

Control verbosity using WithLevel. Options include debug, info, warn, and error.

logkit.WithLevel("debug")

Output Format

Choose between json or logfmt for your backend ingestion or local file output.

logkit.WithFormat("json")

Request Context

Inject trace_id and request_id automatically from your HTTP handler context.

Sampling

Reduce noise in production by configuring probabilistic sampling for high-volume events.