Skip to main content

Builder

Struct Builder 

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

日志构建器

Implementations§

Source§

impl Builder

Source

pub fn new() -> Self

Examples found in repository?
examples/quickwit_example.rs (line 18)
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}
Source

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

验证配置的有效性

Source

pub fn builder(self) -> LogResult<()>

Examples found in repository?
examples/quickwit_example.rs (line 24)
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}
Source

pub fn level(self, level: LevelFilter) -> Self

Examples found in repository?
examples/quickwit_example.rs (line 19)
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}
Source

pub fn log_file(self, log_file: String) -> Self

Examples found in repository?
examples/quickwit_example.rs (line 21)
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}
Source

pub fn log_file_max(self, log_file_max: u32) -> Self

Examples found in repository?
examples/quickwit_example.rs (line 22)
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}
Source

pub fn use_console(self, use_console: bool) -> Self

Examples found in repository?
examples/quickwit_example.rs (line 20)
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}
Source

pub fn use_async(self, use_async: bool) -> Self

Source

pub fn level_str(self, level: &str) -> LogResult<Self>

Source

pub fn log_file_max_str(self, log_file_max: &str) -> LogResult<Self>

Source

pub fn plugin<T: Write + Send + Sync + 'static>(self, plugin: T) -> Self

Source

pub fn filter(self, filter: impl CustomFilter) -> Self

Source

pub fn show_process_id(self, show: bool) -> Self

设置是否显示进程ID

Source

pub fn show_thread_info(self, show: bool) -> Self

设置是否显示线程信息

Source

pub fn show_module_path(self, show: bool) -> Self

设置是否显示模块路径

Source

pub fn highlight_keywords(self, keywords: Vec<String>) -> Self

设置需要高亮显示的关键词

Source

pub fn add_highlight_keyword(self, keyword: String) -> Self

添加单个关键词到高亮列表

Source

pub fn quickwit(self, config: QuickwitConfig) -> Self

设置 Quickwit 配置

Examples found in repository?
examples/quickwit_example.rs (line 23)
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}
Source

pub fn quickwit_simple(self, url: String, index_id: String) -> Self

设置 Quickwit URL 和索引 ID

Source

pub fn disable_quickwit(self) -> Self

禁用 Quickwit

Trait Implementations§

Source§

impl Default for Builder

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> 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.