pub struct QuickwitClient { /* private fields */ }Expand description
Quickwit 客户端
Implementations§
Source§impl QuickwitClient
impl QuickwitClient
Sourcepub fn new(config: QuickwitConfig) -> LogResult<Self>
pub fn new(config: QuickwitConfig) -> LogResult<Self>
创建新的 Quickwit 客户端
Examples found in repository?
examples/test_quickwit.rs (line 22)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9 println!("开始测试 Quickwit 连接...");
10
11 // 创建 Quickwit 配置(不使用 token)
12 let config = QuickwitConfig::new(
13 "http://localhost:7280".to_string(),
14 "log_full".to_string(),
15 )
16 .with_timeout(10)
17 .with_batch_size(1);
18
19 println!("配置: {:?}", config);
20
21 // 创建客户端
22 let client = match QuickwitClient::new(config) {
23 Ok(client) => {
24 println!("✓ Quickwit 客户端创建成功");
25 client
26 },
27 Err(e) => {
28 println!("✗ Quickwit 客户端创建失败: {}", e);
29 return Err(e.into());
30 }
31 };
32
33 // 创建测试日志条目
34 let log_entry = QuickwitLogEntry {
35 timestamp: std::time::SystemTime::now()
36 .duration_since(std::time::UNIX_EPOCH)
37 .unwrap()
38 .as_secs(),
39 level: "INFO".to_string(),
40 message: "测试日志条目 - Quickwit 连接测试".to_string(),
41 module: Some("test_quickwit".to_string()),
42 file: Some("test_quickwit.rs".to_string()),
43 line: Some(42),
44 process_id: Some(std::process::id()),
45 thread_id: Some("main".to_string()),
46 custom_fields: HashMap::new(),
47 };
48
49 println!("准备发送测试日志条目...");
50
51 // 发送日志
52 match client.send_log(&log_entry) {
53 Ok(()) => {
54 println!("✓ 日志发送成功!");
55 println!("请检查 Quickwit 索引 'log_full' 中是否有新的日志条目");
56 },
57 Err(e) => {
58 println!("✗ 日志发送失败: {}", e);
59 println!("可能的原因:");
60 println!(" 1. Quickwit 服务未运行 (检查 http://localhost:7280)");
61 println!(" 2. 索引 'log_full' 不存在");
62 println!(" 3. 网络连接问题");
63 println!(" 4. Quickwit 配置错误");
64 return Err(e.into());
65 }
66 }
67
68 println!("测试完成!");
69 Ok(())
70}Sourcepub fn with_client(self, client: Arc<dyn HttpClient + Send + Sync>) -> Self
pub fn with_client(self, client: Arc<dyn HttpClient + Send + Sync>) -> Self
设置自定义 HTTP 客户端
Sourcepub fn send_log(&self, entry: &QuickwitLogEntry) -> LogResult<()>
pub fn send_log(&self, entry: &QuickwitLogEntry) -> LogResult<()>
发送单个日志条目
Examples found in repository?
examples/test_quickwit.rs (line 52)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9 println!("开始测试 Quickwit 连接...");
10
11 // 创建 Quickwit 配置(不使用 token)
12 let config = QuickwitConfig::new(
13 "http://localhost:7280".to_string(),
14 "log_full".to_string(),
15 )
16 .with_timeout(10)
17 .with_batch_size(1);
18
19 println!("配置: {:?}", config);
20
21 // 创建客户端
22 let client = match QuickwitClient::new(config) {
23 Ok(client) => {
24 println!("✓ Quickwit 客户端创建成功");
25 client
26 },
27 Err(e) => {
28 println!("✗ Quickwit 客户端创建失败: {}", e);
29 return Err(e.into());
30 }
31 };
32
33 // 创建测试日志条目
34 let log_entry = QuickwitLogEntry {
35 timestamp: std::time::SystemTime::now()
36 .duration_since(std::time::UNIX_EPOCH)
37 .unwrap()
38 .as_secs(),
39 level: "INFO".to_string(),
40 message: "测试日志条目 - Quickwit 连接测试".to_string(),
41 module: Some("test_quickwit".to_string()),
42 file: Some("test_quickwit.rs".to_string()),
43 line: Some(42),
44 process_id: Some(std::process::id()),
45 thread_id: Some("main".to_string()),
46 custom_fields: HashMap::new(),
47 };
48
49 println!("准备发送测试日志条目...");
50
51 // 发送日志
52 match client.send_log(&log_entry) {
53 Ok(()) => {
54 println!("✓ 日志发送成功!");
55 println!("请检查 Quickwit 索引 'log_full' 中是否有新的日志条目");
56 },
57 Err(e) => {
58 println!("✗ 日志发送失败: {}", e);
59 println!("可能的原因:");
60 println!(" 1. Quickwit 服务未运行 (检查 http://localhost:7280)");
61 println!(" 2. 索引 'log_full' 不存在");
62 println!(" 3. 网络连接问题");
63 println!(" 4. Quickwit 配置错误");
64 return Err(e.into());
65 }
66 }
67
68 println!("测试完成!");
69 Ok(())
70}Sourcepub fn send_logs(&self, entries: &[QuickwitLogEntry]) -> LogResult<()>
pub fn send_logs(&self, entries: &[QuickwitLogEntry]) -> LogResult<()>
批量发送日志条目
Auto Trait Implementations§
impl !RefUnwindSafe for QuickwitClient
impl !UnwindSafe for QuickwitClient
impl Freeze for QuickwitClient
impl Send for QuickwitClient
impl Sync for QuickwitClient
impl Unpin for QuickwitClient
impl UnsafeUnpin for QuickwitClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more