use log_full::quickwit::{QuickwitConfig, QuickwitClient, QuickwitLogEntry};
use std::collections::HashMap;
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("开始测试 Quickwit 连接...");
let config = QuickwitConfig::new(
"http://localhost:7280".to_string(),
"log_full".to_string(),
)
.with_timeout(10)
.with_batch_size(1);
println!("配置: {:?}", config);
let client = match QuickwitClient::new(config) {
Ok(client) => {
println!("✓ Quickwit 客户端创建成功");
client
},
Err(e) => {
println!("✗ Quickwit 客户端创建失败: {}", e);
return Err(e.into());
}
};
let log_entry = QuickwitLogEntry {
timestamp: std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_secs(),
level: "INFO".to_string(),
message: "测试日志条目 - Quickwit 连接测试".to_string(),
module: Some("test_quickwit".to_string()),
file: Some("test_quickwit.rs".to_string()),
line: Some(42),
process_id: Some(std::process::id()),
thread_id: Some("main".to_string()),
custom_fields: HashMap::new(),
};
println!("准备发送测试日志条目...");
match client.send_log(&log_entry) {
Ok(()) => {
println!("✓ 日志发送成功!");
println!("请检查 Quickwit 索引 'log_full' 中是否有新的日志条目");
},
Err(e) => {
println!("✗ 日志发送失败: {}", e);
println!("可能的原因:");
println!(" 1. Quickwit 服务未运行 (检查 http://localhost:7280)");
println!(" 2. 索引 'log_full' 不存在");
println!(" 3. 网络连接问题");
println!(" 4. Quickwit 配置错误");
return Err(e.into());
}
}
println!("测试完成!");
Ok(())
}