Local Logs & Debugging
Read program logs, compute unit consumption, and transaction errors on local validators without RPC rate limits.
Recipe
Quick-reference recipe card - copy-paste ready.
solana-test-validator
solana logs
anchor test
solana confirm -v <SIGNATURE>When to reach for this:
- Iterating on
msg!output during instruction development. - Measuring CU before mainnet deploy.
- Debugging Anchor test failures with full meta.
- Comparing local vs devnet error codes.
Working Example
# Terminal 1
solana-test-validator --reset
# Terminal 2
solana config set --url http://127.0.0.1:8899
solana logs
# Terminal 3
anchor test --skip-local-validator
# After failure, inspect signature from test output
solana confirm -v <SIG>What this demonstrates:
- Validator stdout and
solana logsboth surface program output. - Anchor tests print signatures on failure for
confirm -vfollow-up. - Local environment removes devnet RPC noise from debugging.
Deep Dive
How It Works
- Programs log via
msg!,sol_log, andsol_log_compute_units. - Transaction meta includes
logMessagesandcomputeUnitsConsumed. - Failed transactions still return logs up to the failing instruction.
- Local validator allows unlimited
simulateTransactioncalls.
Debug Checklist
| Signal | Tool | Action |
|---|---|---|
| Program lines | solana logs | Trace instruction path |
| Error code | confirm -v | Map to program Error enum |
| CU usage | meta field | Tune compute budget ix |
| Account state | solana account | Verify owners and data |
bash Notes
# Anchor verbose test
anchor test -- --nocapture
# RUST_LOG for off-chain test harness
RUST_LOG=debug anchor testGotchas
- Log spam hits limits - excessive
msg!truncates logs and burns CU. Fix: log discriminators and summaries only. - Missing logs on success path - instruction skipped due to early guard. Fix: log at branch entry points.
- Ignoring CU in local tests - passes locally, fails on congested mainnet. Fix: set compute budget based on simulated CU with headroom.
- Wrong terminal order - logs subscriber starts after tx. Fix: start
solana logsbefore sending transactions. - Confusing validator stdout with RPC logs - both show output; correlate with signatures. Fix: include signature in
msg!only in dev builds.
Alternatives
| Alternative | Use When | Don't Use When |
|---|---|---|
| LiteSVM tests | Sub-second Rust unit loops | Wallet client debugging |
simulateTransaction | Client-side preflight | Streaming live traffic |
| Surfpool simulate | Mainnet-fork scenarios | Minimal program-only work |
devnet solana logs | Shared repro with teammates | Fast inner loop |
FAQs
Where do anchor test logs go?
Test validator stdout and solana logs - enable -- --nocapture for Rust test println output.
How do I see CU per instruction?
Use sol_log_compute_units in program or read total computeUnitsConsumed in meta after optimize passes.
Why are logs truncated?
Solana caps log bytes per transaction - reduce verbosity.
Can I filter logs by program ID?
solana logs supports mention filters - see solana logs --help.
Do CPI logs appear?
Yes - inner invocations indent in logMessages order.
How do I debug custom program errors?
Map numeric codes to #[error_code] enums in Anchor or manual ProgramError variants.
Does local debugging match mainnet?
Execution semantics align on Agave 4.1.1; congestion and priority fee paths differ.
Can I save logs to file?
Redirect solana logs or capture JSON meta from solana transaction.
What about LiteSVM logs?
LiteSVM 0.6.x captures logs in test assertions without WebSocket subscriptions.
How do I debug compute budget?
Add ComputeBudgetInstruction::set_compute_unit_limit in client and compare consumed vs limit in meta.
Related
- Logs & Debugging - CLI log commands
- solana-test-validator - local cluster
- Estimating Compute Units - CU tuning
- Testing Basics - test pyramid
Stack versions: This page was written for Agave 4.1.1, Solana CLI 3.0.10, Anchor 0.32.1, anchor-lang 0.32.1, Rust 1.91.1, @solana/kit 7.0.0, Surfpool 0.12.0, and LiteSVM 0.6.x.