Skip to content

Commit b979127

Browse files
committed
feat: format tx logs in light program test
1 parent e3b63d3 commit b979127

File tree

18 files changed

+3159
-22
lines changed

18 files changed

+3159
-22
lines changed

CLAUDE.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Light Protocol Enhanced Logging
2+
3+
## Transaction Log File
4+
5+
The light-program-test library automatically creates detailed transaction logs in:
6+
```
7+
target/light_program_test.log
8+
```
9+
10+
### Features
11+
12+
- **Always enabled**: Logs are written to file regardless of environment variables
13+
- **Clean format**: Plain text without ANSI color codes for easy reading and processing
14+
- **Session-based**: Each test session starts with a timestamp header, transactions append to the same file
15+
- **Comprehensive details**: Includes transaction signatures, fees, compute usage, instruction hierarchies, Light Protocol instruction parsing, and compressed account information
16+
17+
### Configuration
18+
19+
Enhanced logging is enabled by default. To disable:
20+
```rust
21+
let mut config = ProgramTestConfig::default();
22+
config.enhanced_logging.enabled = false;
23+
```
24+
25+
Console output requires `RUST_BACKTRACE` environment variable and can be controlled separately from file logging.
26+
27+
### Log File Location
28+
29+
The log file is automatically placed in the cargo workspace target directory, making it consistent across different test environments and working directories.

Cargo.lock

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ arrayvec = "0.7"
197197

198198
# Math and crypto
199199
num-bigint = "0.4.6"
200+
tabled = "0.20"
200201
num-traits = "0.2.19"
201202
zerocopy = { version = "0.8.25" }
202203
base64 = "0.13"

program-tests/registry-test/tests/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ async fn test_initialize_protocol_config() {
193193
test_accounts: TestAccounts::get_program_test_test_accounts(),
194194
payer,
195195
config: ProgramTestConfig::default(),
196+
transaction_counter: 0,
196197
};
197198

198199
let payer = rpc.get_payer().insecure_clone();

sdk-libs/program-test/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,9 @@ solana-account = { workspace = true }
5151
solana-compute-budget = { workspace = true }
5252
rand = { workspace = true }
5353
bytemuck = { workspace = true }
54+
serde = { workspace = true }
55+
serde_json = { workspace = true }
56+
solana-transaction-status = { workspace = true }
57+
bs58 = { workspace = true }
58+
light-sdk-types = { workspace = true }
59+
tabled = { workspace = true }

sdk-libs/program-test/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
115115
pub mod accounts;
116116
pub mod indexer;
117+
pub mod logging;
117118
pub mod program_test;
118119
pub mod utils;
119120

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
//! Configuration types for enhanced logging
2+
3+
use serde::{Deserialize, Serialize};
4+
5+
/// Configuration for enhanced transaction logging
6+
#[derive(Debug, Clone, Serialize, Deserialize)]
7+
pub struct EnhancedLoggingConfig {
8+
/// Whether enhanced logging is enabled
9+
pub enabled: bool,
10+
/// Whether to log events to console (file logging is always enabled when enhanced_logging.enabled = true)
11+
pub log_events: bool,
12+
/// Level of detail in logs
13+
pub verbosity: LogVerbosity,
14+
/// Show account changes before/after transaction
15+
pub show_account_changes: bool,
16+
/// Decode Light Protocol specific instructions
17+
pub decode_light_instructions: bool,
18+
/// Show compute units consumed per instruction
19+
pub show_compute_units: bool,
20+
/// Use ANSI colors in output
21+
pub use_colors: bool,
22+
/// Maximum number of inner instruction levels to display
23+
pub max_inner_instruction_depth: usize,
24+
/// Show instruction data for account compression program
25+
pub show_compression_instruction_data: bool,
26+
}
27+
28+
impl Default for EnhancedLoggingConfig {
29+
fn default() -> Self {
30+
Self {
31+
enabled: true, // Always enabled for processing
32+
log_events: false, // Don't log by default
33+
verbosity: LogVerbosity::Standard,
34+
show_account_changes: true,
35+
decode_light_instructions: true,
36+
show_compute_units: true,
37+
use_colors: true,
38+
max_inner_instruction_depth: 60,
39+
show_compression_instruction_data: false,
40+
}
41+
}
42+
}
43+
44+
/// Verbosity levels for transaction logging
45+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
46+
pub enum LogVerbosity {
47+
/// Only instruction hierarchy and status
48+
Brief,
49+
/// + account changes and basic instruction info
50+
Standard,
51+
/// + parsed instruction data when available
52+
Detailed,
53+
/// + raw instruction data and internal debugging info
54+
Full,
55+
}
56+
57+
impl EnhancedLoggingConfig {
58+
/// Create config optimized for debugging
59+
pub fn debug() -> Self {
60+
Self {
61+
enabled: true,
62+
log_events: true, // Enable logging for debug mode
63+
verbosity: LogVerbosity::Full,
64+
show_account_changes: true,
65+
decode_light_instructions: true,
66+
show_compute_units: true,
67+
use_colors: true,
68+
max_inner_instruction_depth: 60,
69+
show_compression_instruction_data: false,
70+
}
71+
}
72+
73+
/// Create config optimized for CI/production
74+
pub fn minimal() -> Self {
75+
Self {
76+
enabled: true,
77+
log_events: false, // Don't log for minimal config
78+
verbosity: LogVerbosity::Brief,
79+
show_account_changes: false,
80+
decode_light_instructions: false,
81+
show_compute_units: false,
82+
use_colors: false,
83+
max_inner_instruction_depth: 60,
84+
show_compression_instruction_data: false,
85+
}
86+
}
87+
88+
/// Create config based on environment - always enabled, debug level when RUST_BACKTRACE is set
89+
pub fn from_env() -> Self {
90+
if std::env::var("RUST_BACKTRACE").is_ok() {
91+
Self::debug()
92+
} else {
93+
// Always enabled but with standard verbosity when backtrace is not set
94+
Self::default()
95+
}
96+
}
97+
98+
/// Enable event logging with current settings
99+
pub fn with_logging(mut self) -> Self {
100+
self.log_events = true;
101+
self
102+
}
103+
104+
/// Disable event logging
105+
pub fn without_logging(mut self) -> Self {
106+
self.log_events = false;
107+
self
108+
}
109+
}

0 commit comments

Comments
 (0)