Skip to main content
Stagehand provides comprehensive logging capabilities to help you debug automation workflows, track execution, and diagnose issues. Configure logging levels, structured output, and debugging tools for both development and production environments.

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:
Use for: Development, debugging specific issues

Log Destinations

Logs can be sent to different destinations, including your console and external observability platforms:
Fast, structured, colorized JSON logger with console output.When to use: Development, staging, or production without external observability; can manage multiple Stagehand instances
  • process.env.NODE_ENV === "test"
  • process.env.JEST_WORKER_ID !== undefined (Jest tests)
  • process.env.PLAYWRIGHT_TEST_BASE_DIR !== undefined (Playwright tests)
  • process.env.CI === "true" (CI/CD environments)
Why auto-disable? Pino uses worker threads for pretty-printing, which can cause issues in test runners.

File-Based Session Logging

Enable detailed file-based logging for all Stagehand operations by setting a config directory. This creates comprehensive logs for agent.execute, act, observe, extract, CDP events, and LLM requests/responses.

Setup

Add to your shell configuration (~/.zshrc, ~/.bashrc, etc.):
Then reload your shell or run source ~/.zshrc.

Usage

Run your Stagehand script as normal:
Logs are written to ~/.config/browserbase/sessions/<session-id>/ with a latest symlink pointing to the most recent session.

Viewing Logs

Follow all logs as they happen:
Or watch specific log types:

Log Files

Each session directory contains:
This is especially useful for debugging agent workflows where you need to trace the full sequence of LLM decisions, browser actions, and CDP interactions.

LLM Inference Debugging

Development only - Creates large files and contains page content. Do not use in production.
Save complete LLM request/response dumps to disk for offline analysis. See exactly what DOM was sent to the LLM and why it chose the wrong element.
Creates timestamped files for each LLM call:
File Types:
Contains the complete LLM request:
Contains the LLM output:
Aggregates all calls with metrics:

Reference

Logging Configuration

All logging options are passed to the Stagehand constructor:

Log Structure

Each log entry follows a structured format:

Next Steps

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

History API

Track all LLM operations (act, extract, observe, agent) with parameters, results, and timestamps. Perfect for debugging sequences and replaying workflows.

Metrics API

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

LLM Inference Debugging

Save complete LLM request/response dumps to disk. See exactly what DOM was sent to the LLM and why it made specific decisions.

Browserbase Session Monitoring

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