Skip to main content

QuickwitConfig

Struct QuickwitConfig 

Source
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: String

Quickwit 服务器 URL

§index_id: String

索引 ID

§timeout: u64

连接超时时间(秒)

§batch_size: usize

批量发送大小

§enabled: bool

是否启用

§token: Option<String>

认证 token(可选)

Implementations§

Source§

impl QuickwitConfig

Source

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

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

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

pub fn with_token<T: Into<String>>(self, token: T) -> Self

设置认证 token

Source

pub fn validate(&self) -> LogResult<()>

验证配置

Trait Implementations§

Source§

impl Clone for QuickwitConfig

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl Debug for QuickwitConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for QuickwitConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.