Skip to content

Log Types

This page documents all log types, the LogEntry structure, and how custom types work.

Log Level

Controls the severity of a log entry.

ValueDescription
debugLow-level diagnostic information
infoNormal operational events (default)
errorError conditions that require attention

Categories and Types

Log types are organized into named categories. Categories are resolved automatically from the type field during ingestion.

AiLogType

Types in the ai category for AI/LLM tracing:

TypeDescription
llmLLM API call -- input, output, model, token usage
interactionUser interaction event
stepA discrete step in a workflow or agent loop
actionAn action taken by an agent or system
responseA response produced -- to the user or to another system
summaryA summary or rollup of a session or process

HttpLogType

Types in the http category:

TypeDescription
requestAn inbound HTTP request
responseAn outbound HTTP response

SystemLogType

Types in the system category:

TypeDescription
errorAn error event with structured context
debugDebug-specific output
infoInformational event
warnWarning -- non-fatal but noteworthy
logGeneric log entry (default type)

BuiltInLogType

The union of all built-in types:

typescript
type BuiltInLogType = AiLogType | HttpLogType | SystemLogType

Custom Types

Any type string not matching a built-in type is assigned the custom category. The type field accepts any non-empty string.

LogPayload

The request body sent when ingesting a log entry:

typescript
interface LogPayload {
  message: string                    // Required, min 1 character
  level?: 'debug' | 'info' | 'error' // Defaults to 'info'
  type?: string                      // Defaults to 'log', any non-empty string
  sessionId?: string                 // Groups related logs in a session
  data?: Record<string, unknown>     // Arbitrary structured metadata
  timestamp?: number                 // Unix milliseconds, defaults to Date.now()
}

Example:

json
{
  "message": "Model inference completed",
  "level": "info",
  "type": "llm",
  "sessionId": "sess_abc123",
  "data": {
    "model": "claude-3",
    "tokens": 512,
    "latencyMs": 890
  },
  "timestamp": 1709812800000
}

LogEntry

The internal representation used by the client SDK:

typescript
interface LogEntry {
  projectId: string
  sessionId: string
  message: string
  level: 'debug' | 'info' | 'error'
  type: string
  data?: Record<string, unknown>
  timestamp: number
}

LogRecord

The shape stored in D1 and returned by query endpoints:

typescript
interface LogRecord {
  id: number
  project_id: string
  session_id: string | null
  type: string
  category: string | null     // Resolved: 'ai' | 'http' | 'system' | 'custom'
  level: string
  message: string
  timestamp: number           // Unix milliseconds
  data: string | null         // JSON-serialized string of the original data object
}

Category Resolution

Categories are resolved server-side using the resolveCategory() function from src/types/categories.ts:

typescript
const LOG_CATEGORIES = {
  ai: ['llm', 'interaction', 'step', 'action', 'response', 'summary'],
  http: ['request', 'response'],
  system: ['error', 'debug', 'info', 'warn', 'log'],
} as const

function resolveCategory(type: string): LogCategory | 'custom' {
  return categoryByType.get(type) ?? 'custom'
}

The function checks the type against a pre-built map of all built-in types. If no match is found, it returns 'custom'.

Ambiguous types

The response type appears in both ai and http categories. It maps to ai (first match). Use the category filter in queries if you need to distinguish between them.

See Also

LogVista — Edge-native structured logging API