pub struct Builder { /* private fields */ }Expand description
日志构建器
Implementations§
Source§impl Builder
impl Builder
Sourcepub fn new() -> Self
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}Sourcepub fn builder(self) -> LogResult<()>
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}Sourcepub fn level(self, level: LevelFilter) -> Self
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}Sourcepub fn log_file(self, log_file: String) -> Self
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}Sourcepub fn log_file_max(self, log_file_max: u32) -> Self
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}Sourcepub fn use_console(self, use_console: bool) -> Self
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}pub fn use_async(self, use_async: bool) -> Self
pub fn level_str(self, level: &str) -> LogResult<Self>
pub fn log_file_max_str(self, log_file_max: &str) -> LogResult<Self>
pub fn plugin<T: Write + Send + Sync + 'static>(self, plugin: T) -> Self
pub fn filter(self, filter: impl CustomFilter) -> Self
Sourcepub fn show_process_id(self, show: bool) -> Self
pub fn show_process_id(self, show: bool) -> Self
设置是否显示进程ID
Sourcepub fn show_thread_info(self, show: bool) -> Self
pub fn show_thread_info(self, show: bool) -> Self
设置是否显示线程信息
Sourcepub fn show_module_path(self, show: bool) -> Self
pub fn show_module_path(self, show: bool) -> Self
设置是否显示模块路径
Sourcepub fn highlight_keywords(self, keywords: Vec<String>) -> Self
pub fn highlight_keywords(self, keywords: Vec<String>) -> Self
设置需要高亮显示的关键词
Sourcepub fn add_highlight_keyword(self, keyword: String) -> Self
pub fn add_highlight_keyword(self, keyword: String) -> Self
添加单个关键词到高亮列表
Sourcepub fn quickwit(self, config: QuickwitConfig) -> Self
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}Sourcepub fn quickwit_simple(self, url: String, index_id: String) -> Self
pub fn quickwit_simple(self, url: String, index_id: String) -> Self
设置 Quickwit URL 和索引 ID
Sourcepub fn disable_quickwit(self) -> Self
pub fn disable_quickwit(self) -> Self
禁用 Quickwit
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Builder
impl !UnwindSafe for Builder
impl Freeze for Builder
impl Send for Builder
impl Sync for Builder
impl Unpin for Builder
impl UnsafeUnpin for Builder
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