Skip to content

feat: format tx logs in light program test #1903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Light Protocol Enhanced Logging

## Transaction Log File

The light-program-test library automatically creates detailed transaction logs in:
```
target/light_program_test.log
```

### Features

- **Always enabled**: Logs are written to file regardless of environment variables
- **Clean format**: Plain text without ANSI color codes for easy reading and processing
- **Session-based**: Each test session starts with a timestamp header, transactions append to the same file
- **Comprehensive details**: Includes transaction signatures, fees, compute usage, instruction hierarchies, Light Protocol instruction parsing, and compressed account information

### Configuration

Enhanced logging is enabled by default. To disable:
```rust
let mut config = ProgramTestConfig::default();
config.enhanced_logging.enabled = false;
```

Console output requires `RUST_BACKTRACE` environment variable and can be controlled separately from file logging.

### Log File Location

The log file is automatically placed in the cargo workspace target directory, making it consistent across different test environments and working directories.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ arrayvec = "0.7"

# Math and crypto
num-bigint = "0.4.6"
tabled = "0.20"
num-traits = "0.2.19"
zerocopy = { version = "0.8.25" }
base64 = "0.13"
Expand Down
1 change: 1 addition & 0 deletions program-tests/registry-test/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ async fn test_initialize_protocol_config() {
test_accounts: TestAccounts::get_program_test_test_accounts(),
payer,
config: ProgramTestConfig::default(),
transaction_counter: 0,
};

let payer = rpc.get_payer().insecure_clone();
Expand Down
7 changes: 7 additions & 0 deletions sdk-libs/program-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,10 @@ solana-account = { workspace = true }
solana-compute-budget = { workspace = true }
rand = { workspace = true }
bytemuck = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
solana-transaction-status = { workspace = true }
bs58 = { workspace = true }
light-sdk-types = { workspace = true }
tabled = { workspace = true }
chrono = "0.4"
1 change: 1 addition & 0 deletions sdk-libs/program-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@

pub mod accounts;
pub mod indexer;
pub mod logging;
pub mod program_test;
pub mod utils;

Expand Down
109 changes: 109 additions & 0 deletions sdk-libs/program-test/src/logging/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
//! Configuration types for enhanced logging

use serde::{Deserialize, Serialize};

/// Configuration for enhanced transaction logging
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EnhancedLoggingConfig {
/// Whether enhanced logging is enabled
pub enabled: bool,
/// Whether to log events to console (file logging is always enabled when enhanced_logging.enabled = true)
pub log_events: bool,
/// Level of detail in logs
pub verbosity: LogVerbosity,
/// Show account changes before/after transaction
pub show_account_changes: bool,
/// Decode Light Protocol specific instructions
pub decode_light_instructions: bool,
/// Show compute units consumed per instruction
pub show_compute_units: bool,
/// Use ANSI colors in output
pub use_colors: bool,
/// Maximum number of inner instruction levels to display
pub max_inner_instruction_depth: usize,
/// Show instruction data for account compression program
pub show_compression_instruction_data: bool,
}

impl Default for EnhancedLoggingConfig {
fn default() -> Self {
Self {
enabled: true, // Always enabled for processing
log_events: false, // Don't log by default
verbosity: LogVerbosity::Standard,
show_account_changes: true,
decode_light_instructions: true,
show_compute_units: true,
use_colors: true,
max_inner_instruction_depth: 60,
show_compression_instruction_data: false,
}
}
}

/// Verbosity levels for transaction logging
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum LogVerbosity {
/// Only instruction hierarchy and status
Brief,
/// + account changes and basic instruction info
Standard,
/// + parsed instruction data when available
Detailed,
/// + raw instruction data and internal debugging info
Full,
}

impl EnhancedLoggingConfig {
/// Create config optimized for debugging
pub fn debug() -> Self {
Self {
enabled: true,
log_events: true, // Enable logging for debug mode
verbosity: LogVerbosity::Full,
show_account_changes: true,
decode_light_instructions: true,
show_compute_units: true,
use_colors: true,
max_inner_instruction_depth: 60,
show_compression_instruction_data: false,
}
}

/// Create config optimized for CI/production
pub fn minimal() -> Self {
Self {
enabled: true,
log_events: false, // Don't log for minimal config
verbosity: LogVerbosity::Brief,
show_account_changes: false,
decode_light_instructions: false,
show_compute_units: false,
use_colors: false,
max_inner_instruction_depth: 60,
show_compression_instruction_data: false,
}
}

/// Create config based on environment - always enabled, debug level when RUST_BACKTRACE is set
pub fn from_env() -> Self {
if std::env::var("RUST_BACKTRACE").is_ok() {
Self::debug()
} else {
// Always enabled but with standard verbosity when backtrace is not set
Self::default()
}
}

/// Enable event logging with current settings
pub fn with_logging(mut self) -> Self {
self.log_events = true;
self
}

/// Disable event logging
pub fn without_logging(mut self) -> Self {
self.log_events = false;
self
}
}
Loading
Loading