pub struct QuickwitConfig {
pub url: String,
pub index_id: String,
pub timeout: u64,
pub batch_size: usize,
pub enabled: bool,
pub token: Option<String>,
}Expand description
Quickwit 配置
Fields§
§url: StringQuickwit 服务器 URL
index_id: String索引 ID
timeout: u64连接超时时间(秒)
batch_size: usize批量发送大小
enabled: bool是否启用
token: Option<String>认证 token(可选)
Implementations§
Source§impl QuickwitConfig
impl QuickwitConfig
Sourcepub fn new(url: String, index_id: String) -> Self
pub fn new(url: String, index_id: String) -> Self
创建新的 Quickwit 配置
Examples found in repository?
examples/quickwit_example.rs (line 13)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11 // 配置 Quickwit(带 token 认证)
12 let quickwit_config =
13 QuickwitConfig::new("http://localhost:7280".to_string(), "log_full".to_string())
14 .with_timeout(30)
15 .with_batch_size(50); // 可选的认证 token
16
17 // 使用 Builder 配置日志器,包含 Quickwit 功能
18 Builder::new()
19 .level(log::LevelFilter::Info)
20 .use_console(true)
21 .log_file("logs/quickwit_example.log".to_string())
22 .log_file_max(10 * 1024 * 1024) // 10MB
23 .quickwit(quickwit_config)
24 .builder()?;
25
26 loop {
27 // 记录一些测试日志
28 info!("这是一条信息日志,将被发送到 Quickwit");
29 warn!("这是一条警告日志,包含关键信息: user_id=12345");
30 error!("这是一条错误日志,错误代码: E001");
31
32 // 记录带有结构化数据的日志
33 info!(
34 "用户登录成功: user={}, ip={}, timestamp={}",
35 "alice",
36 "192.168.1.100",
37 std::time::SystemTime::now()
38 .duration_since(std::time::UNIX_EPOCH)
39 .unwrap()
40 .as_secs()
41 );
42
43 println!("日志已记录并发送到 Quickwit(如果配置正确)");
44 println!("请检查 Quickwit 索引 'log_full' 中的日志条目");
45
46 // 确保所有异步日志都被处理
47 log::logger().flush();
48 std::thread::sleep(std::time::Duration::from_millis(1000));
49
50 println!("所有日志处理完成");
51 thread::sleep(time::Duration::from_secs(3));
52 }
53
54 // Ok(())
55}More examples
examples/test_quickwit.rs (lines 12-15)
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_timeout(self, timeout: u64) -> Self
pub fn with_timeout(self, timeout: u64) -> Self
设置超时时间
Examples found in repository?
examples/quickwit_example.rs (line 14)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11 // 配置 Quickwit(带 token 认证)
12 let quickwit_config =
13 QuickwitConfig::new("http://localhost:7280".to_string(), "log_full".to_string())
14 .with_timeout(30)
15 .with_batch_size(50); // 可选的认证 token
16
17 // 使用 Builder 配置日志器,包含 Quickwit 功能
18 Builder::new()
19 .level(log::LevelFilter::Info)
20 .use_console(true)
21 .log_file("logs/quickwit_example.log".to_string())
22 .log_file_max(10 * 1024 * 1024) // 10MB
23 .quickwit(quickwit_config)
24 .builder()?;
25
26 loop {
27 // 记录一些测试日志
28 info!("这是一条信息日志,将被发送到 Quickwit");
29 warn!("这是一条警告日志,包含关键信息: user_id=12345");
30 error!("这是一条错误日志,错误代码: E001");
31
32 // 记录带有结构化数据的日志
33 info!(
34 "用户登录成功: user={}, ip={}, timestamp={}",
35 "alice",
36 "192.168.1.100",
37 std::time::SystemTime::now()
38 .duration_since(std::time::UNIX_EPOCH)
39 .unwrap()
40 .as_secs()
41 );
42
43 println!("日志已记录并发送到 Quickwit(如果配置正确)");
44 println!("请检查 Quickwit 索引 'log_full' 中的日志条目");
45
46 // 确保所有异步日志都被处理
47 log::logger().flush();
48 std::thread::sleep(std::time::Duration::from_millis(1000));
49
50 println!("所有日志处理完成");
51 thread::sleep(time::Duration::from_secs(3));
52 }
53
54 // Ok(())
55}More examples
examples/test_quickwit.rs (line 16)
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_batch_size(self, batch_size: usize) -> Self
pub fn with_batch_size(self, batch_size: usize) -> Self
设置批量大小
Examples found in repository?
examples/quickwit_example.rs (line 15)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11 // 配置 Quickwit(带 token 认证)
12 let quickwit_config =
13 QuickwitConfig::new("http://localhost:7280".to_string(), "log_full".to_string())
14 .with_timeout(30)
15 .with_batch_size(50); // 可选的认证 token
16
17 // 使用 Builder 配置日志器,包含 Quickwit 功能
18 Builder::new()
19 .level(log::LevelFilter::Info)
20 .use_console(true)
21 .log_file("logs/quickwit_example.log".to_string())
22 .log_file_max(10 * 1024 * 1024) // 10MB
23 .quickwit(quickwit_config)
24 .builder()?;
25
26 loop {
27 // 记录一些测试日志
28 info!("这是一条信息日志,将被发送到 Quickwit");
29 warn!("这是一条警告日志,包含关键信息: user_id=12345");
30 error!("这是一条错误日志,错误代码: E001");
31
32 // 记录带有结构化数据的日志
33 info!(
34 "用户登录成功: user={}, ip={}, timestamp={}",
35 "alice",
36 "192.168.1.100",
37 std::time::SystemTime::now()
38 .duration_since(std::time::UNIX_EPOCH)
39 .unwrap()
40 .as_secs()
41 );
42
43 println!("日志已记录并发送到 Quickwit(如果配置正确)");
44 println!("请检查 Quickwit 索引 'log_full' 中的日志条目");
45
46 // 确保所有异步日志都被处理
47 log::logger().flush();
48 std::thread::sleep(std::time::Duration::from_millis(1000));
49
50 println!("所有日志处理完成");
51 thread::sleep(time::Duration::from_secs(3));
52 }
53
54 // Ok(())
55}More examples
examples/test_quickwit.rs (line 17)
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_token<T: Into<String>>(self, token: T) -> Self
pub fn with_token<T: Into<String>>(self, token: T) -> Self
设置认证 token
Trait Implementations§
Source§impl Clone for QuickwitConfig
impl Clone for QuickwitConfig
Source§fn clone(&self) -> QuickwitConfig
fn clone(&self) -> QuickwitConfig
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for QuickwitConfig
impl Debug for QuickwitConfig
Auto Trait Implementations§
impl Freeze for QuickwitConfig
impl RefUnwindSafe for QuickwitConfig
impl Send for QuickwitConfig
impl Sync for QuickwitConfig
impl Unpin for QuickwitConfig
impl UnsafeUnpin for QuickwitConfig
impl UnwindSafe for QuickwitConfig
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