diff --git a/src/main.rs b/src/main.rs index 9f2c56c..997b8fd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -233,12 +233,12 @@ async fn post_weather_data( data: web::Json, pool: web::Data, ) -> impl Responder { - println!("Received weather data, preparing to insert into DB..."); + info!("Received weather data, preparing to insert into DB..."); // 调用 db.rs 中的函数来处理数据库逻辑 match insert_weather_data(pool.get_ref(), &data).await { Ok(inserted_id) => { - println!( + info!( "Successfully inserted weather data with id: {}", inserted_id ); @@ -250,7 +250,7 @@ async fn post_weather_data( })) } Err(error_msg) => { - eprintln!("Database operation failed: {}", error_msg); + error!("Database operation failed: {}", error_msg); // 根据错误信息返回统一格式的错误响应 let mut errcode = 500; if error_msg.starts_with("未找到openid") { @@ -402,7 +402,7 @@ async fn get_weather_details( data } Err(error_msg) => { - eprintln!("获取天气数据详情失败: {}", error_msg); + error!("获取天气数据详情失败: {}", error_msg); let errcode = if error_msg.starts_with("未找到") { 404 } else { @@ -504,13 +504,13 @@ async fn get_weather_brief( None => 10, }; - println!("获取天气数据列表, 页码: {}, 每页条数: {}", page, limit); + debug!("获取天气数据列表, 页码: {}, 每页条数: {}", page, limit); match db::get_weather_list(pool.get_ref(), claims.user_id, page, limit).await { Ok(response) => { // 这里的response是WeatherListResponse类型 // 打印获取到的天气列表和总数 - println!( + debug!( "获取到的天气列表: {:?}, 总条数: {}", response.list, response.total ); @@ -523,7 +523,7 @@ async fn get_weather_brief( })) } Err(error_msg) => { - eprintln!("获取天气数据列表失败: {}", error_msg); + error!("获取天气数据列表失败: {}", error_msg); HttpResponse::Ok().json(serde_json::json!({ "success": false, "errcode": 500, @@ -541,7 +541,7 @@ async fn delete_weather( claims: web::ReqData, ) -> impl Responder { let weather_id = path.into_inner(); - println!("删除天气数据, ID: {}", weather_id); + info!("删除天气数据, ID: {}", weather_id); match db::delete_weather_data(pool.get_ref(), weather_id, claims.user_id).await { Ok(_) => HttpResponse::Ok().json(serde_json::json!({ @@ -549,7 +549,7 @@ async fn delete_weather( "message": format!("天气数据 {} 已成功删除", weather_id) })), Err(error_msg) => { - eprintln!("删除天气数据失败: {}", error_msg); + error!("删除天气数据失败: {}", error_msg); let errcode = if error_msg.starts_with("未找到") { 404 } else { @@ -627,12 +627,12 @@ fn create_server_config( #[actix_web::main] async fn main() -> std::io::Result<()> { if let Err(e) = dotenvy::dotenv() { - eprintln!("警告:加载.env文件失败,使用系统环境变量: {}", e); + error!("警告:加载.env文件失败,使用系统环境变量: {}", e); } // 打印当前 RUST_LOG 的值 let rust_log = std::env::var("RUST_LOG").unwrap_or_else(|_| "未设置".to_string()); - eprintln!("当前 RUST_LOG 级别:{}", rust_log); + error!("当前 RUST_LOG 级别:{}", rust_log); env_logger::init(); info!("logger init successful"); @@ -675,7 +675,7 @@ async fn main() -> std::io::Result<()> { let ssl_builder = match create_ssl_acceptor() { Ok(builder) => builder, Err(e) => { - eprintln!("Failed to create SSL acceptor: {}", e); + error!("Failed to create SSL acceptor: {}", e); continue; } }; @@ -695,9 +695,9 @@ async fn main() -> std::io::Result<()> { break; } Err(e) => { - eprintln!("Failed to bind to {} with HTTPS: {}", addr, e); + error!("Failed to bind to {} with HTTPS: {}", addr, e); if e.kind() == std::io::ErrorKind::PermissionDenied { - eprintln!(" -> Permission denied. Try running with sudo or use a port > 1024"); + error!(" -> Permission denied. Try running with sudo or use a port > 1024"); } continue; }