Emitting Logs
msg! and sol_log_data write to transaction logs consumed by explorers, indexers, and simulations. Use sparingly - each log spends compute units.
Search across all documentation pages
msg! and sol_log_data write to transaction logs consumed by explorers, indexers, and simulations. Use sparingly - each log spends compute units.
solana_program::msg!("vault deposit {}", amount);When to reach for this:
pub fn deposit(amount: u64) -> ProgramResult {
solana_program::msg!("deposit_start amount={}", amount);
if amount == 0 {
solana_program::msg!("deposit_reject zero");
return Err(ProgramError::InvalidArgument);
}
solana_program::msg!("deposit_ok");
Ok(())
}What this demonstrates:
Logs scale with string length and count.
solana_program::log::sol_log_data(&[b"evt", &amount.to_le_bytes()]);| Alternative | Use When | Don't Use When |
|---|---|---|
Anchor emit! | Structured events | Native only |
| Custom error codes | User UX | Internal debug |
| Off-chain simulation traces | Dev only | Production observability |
Transaction meta logMessages.
Bounded by CU and tx limits.
后者 for binary chunks.
Geyser/webhooks parse log lines.
Common for release builds.
Still emitted before failure point.
All logs merged in order.
Yes with simulateTransaction.
Re-profile CU if logging heavily.
For indexer-first design yes.
Wrap msg! in cfg.
OK short term for debug.
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.
Reviewed by Chris St. John·Last updated Jul 16, 2026