Skip to main content

QuickwitClient

Struct QuickwitClient 

Source
pub struct QuickwitClient { /* private fields */ }
Expand description

Quickwit 客户端

Implementations§

Source§

impl QuickwitClient

Source

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}
Source

pub fn with_client(self, client: Arc<dyn HttpClient + Send + Sync>) -> Self

设置自定义 HTTP 客户端

Source

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}
Source

pub fn send_logs(&self, entries: &[QuickwitLogEntry]) -> LogResult<()>

批量发送日志条目

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.