log-full 0.0.1

A simple, asynchronous log library
Documentation
//! 检查 Quickwit 索引中的日志
//!
//! 用于验证日志是否成功发送到 Quickwit

use std::process::Command;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    println!("检查 Quickwit 索引 'log_full' 中的日志...");
    
    // 使用 curl 查询 Quickwit 搜索 API
    let output = Command::new("curl")
        .arg("-s")
        .arg("-X")
        .arg("POST")
        .arg("http://localhost:7280/api/v1/log_full/search")
        .arg("-H")
        .arg("Content-Type: application/json")
        .arg("-d")
        .arg(r#"{"query":"*","max_hits":10,"sort_by":"-timestamp"}"#)
        .output();
    
    match output {
        Ok(output) => {
            if output.status.success() {
                let response = String::from_utf8_lossy(&output.stdout);
                println!("Quickwit 搜索结果:");
                println!("{}", response);
                
                // 检查响应中的日志数据
                if response.contains("\"hits\":[]") {
                    println!("\n✗ 索引中没有找到日志记录");
                } else if response.contains("hits") {
                    println!("\n✓ 找到日志记录!");
                    
                    let test_logs = response.matches("test_quickwit").count();
                    let example_logs = response.matches("quickwit_example").count();
                    
                    if example_logs > 0 {
                        println!("✓ 找到了 {} 条示例程序的日志!", example_logs);
                    }
                    if test_logs > 0 {
                        println!("✓ 找到了 {} 条测试日志", test_logs);
                    }
                    if example_logs == 0 && test_logs > 0 {
                        println!("⚠ 只找到测试日志,示例程序的日志可能发送有问题");
                    }
                    
                    // 计算日志条目数量
                    if let Some(start) = response.find("\"num_hits\": ") {
                        if let Some(end) = response[start..].find(',') {
                            let num_str = &response[start + 12..start + end];
                            println!("总共找到 {} 条日志记录", num_str);
                        }
                    }
                } else {
                    println!("\n响应格式不明确,请手动检查");
                }
            } else {
                let error = String::from_utf8_lossy(&output.stderr);
                println!("查询失败: {}", error);
                println!("可能的原因:");
                println!("  1. Quickwit 服务未运行");
                println!("  2. 索引 'log_full' 不存在");
                println!("  3. curl 命令不可用");
            }
        },
        Err(e) => {
            println!("执行 curl 命令失败: {}", e);
            println!("请确保 curl 已安装并且 Quickwit 服务正在运行");
        }
    }
    
    println!("\n你也可以手动访问 Quickwit UI: http://localhost:7280");
    
    Ok(())
}