Structured Logging

Send structured logs with severity, metadata, and code location. Search, filter, and aggregate in the dashboard.

Severity Levels

Five levels: debug, info, warn, error, fatal.

Properties

Attach any structured data to a log. All properties are stored flat and fully searchable via GQL.

typescript
gl.error("Order processing failed", {
  orderId: "ord_456",
  userId: "user_123",
  amount: 99.99,
  paymentMethod: "stripe",
  errorCode: "insufficient_funds",
  service: "billing",
  env: "production",
})

Default Context

Use defaultContext in the constructor to add fields to every log automatically.

typescript
const gl = new GoodLogs({
  apiKey: "gl_sk_...",
  defaultContext: { service: "api", env: "production", version: "2.1.0" },
})

Code Location

Automatically track where errors originate. In Node.js, the calling function name, file, and line number are auto-captured from the stack trace.

typescript
gl.error("DB timeout", {
  function: "findUser",
  file: "src/repos/user.ts",
  line: 89,
})
// Stored as: findUser@src/repos/user.ts:89

Dashboard Features

  • Search — full-text search on messages
  • Filter by severity — debug/info/warn/error/fatal
  • Time range — 1h, 6h, 24h, 7d, 30d
  • Metadata filters — filter by any key-value pair
  • Aggregate mode — group by severity, message, code location, or time bucket
  • Pagination — browse through large result sets

Warning: Logging from the browser requires a public key with Allow browser logs enabled in project settings. Server-side logging requires a secret key.