light_program_test/logging/
config.rs

1//! Configuration types for enhanced logging
2
3use serde::{Deserialize, Serialize};
4
5/// Configuration for enhanced transaction logging
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub 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
28impl 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)]
46pub 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
57impl 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}