Skip to Content
How-To GuidesTypeScriptLogging from a TypeScript Agent

Logging from a TypeScript Agent

TypeScript agents log using the standard console API. Golem captures stdout and stderr and streams them to golem agent stream and golem agent invoke output.

Quick Start

Use the built-in console methods — no imports or setup needed:

console.log("order created:", orderId); console.info("processing item", itemId); console.warn("retry attempt", attempt, "for request", reqId); console.error("failed to connect to database:", err); console.debug("detailed flow: entered processItem");

Log Levels

MethodBehaviorUse for
console.trace(...)Prints with stack trace to stderrFine-grained debugging with call stack
console.debug(...)Writes to stdoutDebugging information
console.log(...)Writes to stdoutGeneral output
console.info(...)Writes to stdoutMonitoring, normal operations
console.warn(...)Writes to stderrHazardous situations, degraded behavior
console.error(...)Writes to stderrSerious errors

Structured Logging

For structured output, log JSON objects:

console.log(JSON.stringify({ level: "info", event: "order_created", orderId, timestamp: new Date().toISOString(), }));

Or use template literals for readable messages with context:

console.info(`[${agentName}] counter incremented to ${this.count}`);

Viewing Logs

Stream live agent output (stdout and stderr):

golem agent stream '<agent-id>'

Or during an invocation:

golem agent invoke '<agent-id>' '<method>' [args] # Logs stream automatically; use --no-stream to suppress

Key Points

  • No setup neededconsole is available globally in the QuickJS runtime
  • Golem captures both stdout (console.log, console.info, console.debug) and stderr (console.warn, console.error) streams
  • Logs are recorded in the oplog and visible via golem agent stream and golem agent invoke
  • Logging is a side effect — during replay (crash recovery), log output from replayed operations is skipped; only new invocations produce log output
  • The TypeScript SDK does not currently expose a direct wasi:logging/logging binding — use console methods for all logging needs
Last updated on