1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//! Logging Utilities Tests
//!
//! Tests for logging initialization functions.
use blvm_node::config::LoggingConfig;
#[cfg(feature = "json-logging")]
use blvm_node::utils::logging::init_json_logging;
use blvm_node::utils::logging::{init_logging, init_logging_from_config, init_module_logging};
fn env_remove(key: &str) {
unsafe { std::env::remove_var(key) }
}
fn env_set(key: &str, value: &str) {
unsafe { std::env::set_var(key, value) }
}
#[test]
fn test_init_logging_default() {
// Test logging initialization with default settings
// Note: This test verifies the function doesn't panic
// Actual logging behavior is hard to test without capturing output
// Clear RUST_LOG to test default behavior
env_remove("RUST_LOG");
// Should not panic
init_logging(None);
}
#[test]
fn test_init_logging_with_filter() {
// Test logging initialization with custom filter
env_remove("RUST_LOG");
// Should not panic
init_logging(Some("debug"));
}
#[test]
fn test_init_logging_with_rust_log() {
// Test that RUST_LOG takes precedence
env_set("RUST_LOG", "trace");
// Should not panic
init_logging(Some("debug")); // Config filter should be ignored
env_remove("RUST_LOG");
}
#[test]
fn test_init_module_logging_default() {
// Test module logging initialization with default settings
env_remove("RUST_LOG");
// Should not panic
init_module_logging("test_module", None);
}
#[test]
fn test_init_module_logging_with_filter() {
// Test module logging with custom filter
env_remove("RUST_LOG");
// Should not panic
init_module_logging("test_module", Some("debug"));
}
#[test]
fn test_init_module_logging_with_rust_log() {
// Test that RUST_LOG takes precedence for modules too
env_set("RUST_LOG", "info");
// Should not panic
init_module_logging("test_module", Some("debug"));
env_remove("RUST_LOG");
}
// Note: init_json_logging is feature-gated behind "json-logging"
// These tests are skipped if the feature is not enabled
#[cfg(feature = "json-logging")]
mod json_logging_tests {
use super::*;
#[test]
fn test_init_json_logging() {
// Test JSON logging initialization
env_remove("RUST_LOG");
// Should not panic
init_json_logging(None);
}
#[test]
fn test_init_json_logging_with_filter() {
// Test JSON logging with custom filter
env_remove("RUST_LOG");
// Should not panic
init_json_logging(Some("debug"));
}
}
#[test]
fn test_init_logging_from_config_none() {
// Test logging initialization with None config
env_remove("RUST_LOG");
// Should not panic
init_logging_from_config(None);
}
#[test]
fn test_init_logging_from_config() {
// Test logging initialization with config
env_remove("RUST_LOG");
let config = LoggingConfig {
filter: Some("debug".to_string()),
json_format: false,
};
// Should not panic
init_logging_from_config(Some(&config));
}
#[test]
fn test_logging_respects_no_color() {
// Test that logging respects NO_COLOR environment variable
env_set("NO_COLOR", "1");
env_remove("RUST_LOG");
// Should not panic
init_logging(None);
env_remove("NO_COLOR");
}