use loggur::{Loggur, Level, info, progress_span, progress_inc};
use std::thread;
use std::time::Duration;
fn main() {
Loggur::init_with_progress(Level::INFO);
info!("진행 상태 표시 예제를 시작합니다");
{
let total = 50;
let span = progress_span!("기본 진행 상태 표시줄", total);
let _enter = span.enter();
for _ in 0..total {
thread::sleep(Duration::from_millis(50));
progress_inc!(1);
}
}
info!("기본 진행 상태 표시줄 완료!");
{
let spinner = Loggur::spinner();
for i in 0..10 {
thread::sleep(Duration::from_millis(200));
spinner.set_message(format!("작업 처리 중... 단계 {}/10", i + 1));
}
spinner.finish_with_message("스피너 작업 완료!");
}
{
let parent_span = progress_span!("멀티 작업", 3);
let _parent_enter = parent_span.enter();
let handles = (0..3).map(|task_id| {
let task_items = match task_id {
0 => 30,
1 => 50,
_ => 20,
};
thread::spawn(move || {
let span = progress_span!(concat!("작업 ", "{task_id}"), task_items);
let _enter = span.enter();
for _ in 0..task_items {
thread::sleep(Duration::from_millis(match task_id {
0 => 50,
1 => 30,
_ => 70,
}));
progress_inc!(1);
}
info!("작업 {} 완료!", task_id + 1);
})
}).collect::<Vec<_>>();
for handle in handles {
handle.join().unwrap();
}
progress_inc!(3);
}
info!("모든 진행 상태 표시 예제가 완료되었습니다");
}