Skip to main content
Configure logging through a single logging option on Stagehand.create(): a level, an output format, and a callback that receives each record. Use the language selector to see the exact shape your SDK accepts.

Quick start

Choose your logging setup based on your environment:

Operational logging

Real-time event logging during automation execution.

Verbosity level

Control how much detail you see in logs. The level is always applied at the source, so the Stagehand runtime never generates or sends a record below your threshold. Every SDK sets that threshold the same way, and the default is info.
Use for: Development, debugging specific issues
Turning logging off suppresses the record callback as well as console output. Do this when handling passwords or other secrets.

Log destinations

Send logs to your console or through your own callback. The record callback drives every destination, so anything your own code can write to is a valid sink. To forward records to an observability platform, see External logging platforms.
Human-readable, single-line console output written to standard error.When to use: Development and interactive debugging
Each line is [stagehand] LEVEL message {json data}, with the data object omitted when empty. Stagehand writes it to standard error so it never mixes with your program’s own standard output.

External logging platforms

The same log callback, pointed at an observability platform. When to use: Production with Sentry, DataDog, CloudWatch, or a custom observability platform for centralized monitoring and error alerting.

Sentry

1

Create a production logger

2

Pass the logger in your Stagehand instance

DataDog

1

Create a production logger

2

Pass the logger in your Stagehand instance

Failures inside your callback are caught and reported on standard error, so a failing logger will not take down your automation. That covers exceptions and rejected promises in TypeScript and Python, and a panic in Go.

File-based session logging

Route the log callback to a file to get a durable, per-session record of every Stagehand operation: act, observe, extract, LLM inference, and browser events.

Setup

Pick a directory for your session logs and open a file per run:

Usage

Write each record as one JSON line, then run your Stagehand script as normal:

Viewing logs

Follow all logs as they happen:
Or filter by category as they stream:

Log files

Because you own the sink, you decide how records are split. A common layout is one file per concern, keyed off the log category:
This is especially useful for debugging long workflows where you need to trace the full sequence of LLM decisions and browser actions after the fact.

LLM inference debugging

Development only - Produces large volumes of output and contains page content. Do not use in production.
Run at the debug level to see the complete inference path: the snapshot that was captured, the prompt category, the model’s chosen element, and the token counts for each call.
Debug-level records include:
Emitted before each LLM call, carrying the operation and prompt metadata:
Emitted when the model returns, carrying the selected element:
Emitted once per operation with the token and latency accounting:
Token counters are also aggregated across the whole session. See Observability for the cumulative view.

Reference

Logging configuration

Pass all logging options as a single object to Stagehand.create():
The level is also forwarded to the Stagehand runtime, so suppressed records are never generated or sent over the wire. Raising it to debug increases both log volume and message traffic.

Log structure

Each log entry follows a structured format:
Unlike v3’s LogLine, data is a flat JSON object: values are already typed, so there is no { value, type } wrapper to parse. Fields such as category and timestamp appear inside data when the emitting operation provides them.

Next steps

Now that you have logging configured, explore additional debugging and monitoring tools in the Observability guide:

Tracing

Export OpenTelemetry spans for every Stagehand operation to your own collector, with trace context propagated across the SDK and runtime boundary.

Metrics API

Monitor token usage and performance in real-time. Track costs per operation, identify expensive calls, and optimize resource usage.

LLM inference debugging

Run at the debug level to see exactly what Stagehand sent to the model and why the model chose each action.

Browserbase session monitoring

Watch your automation visually with session recordings, network monitoring, and real-time browser inspection (Browserbase only).