diff --git a/gui/Cargo.lock b/gui/Cargo.lock index 622b007..4984145 100644 --- a/gui/Cargo.lock +++ b/gui/Cargo.lock @@ -1312,13 +1312,16 @@ dependencies = [ "dirs 5.0.1", "env_logger", "lazy_static", + "log", "rand", "ratatui", "reqwest", "serde", "serde_json", "serde_yaml", + "simplelog", "sysinfo", + "time", "tokio", "webbrowser", ] @@ -2328,6 +2331,17 @@ dependencies = [ "libc", ] +[[package]] +name = "simplelog" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16257adbfaef1ee58b1363bdc0664c9b8e1e30aed86049635fb5f147d065a9c0" +dependencies = [ + "log", + "termcolor", + "time", +] + [[package]] name = "siphasher" version = "0.3.11" @@ -2490,6 +2504,15 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + [[package]] name = "terminfo" version = "0.8.0" @@ -2583,12 +2606,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35e7868883861bd0e56d9ac6efcaaca0d6d5d82a2a7ec8209ff492c07cf37b21" dependencies = [ "deranged", + "itoa", "libc", "num-conv", "num_threads", "powerfmt", "serde", "time-core", + "time-macros", ] [[package]] @@ -2597,6 +2622,16 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" +[[package]] +name = "time-macros" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2834e6017e3e5e4b9834939793b282bc03b37a3336245fa820e35e233e2a85de" +dependencies = [ + "num-conv", + "time-core", +] + [[package]] name = "tiny-keccak" version = "2.0.2" diff --git a/gui/Cargo.toml b/gui/Cargo.toml index 67fc2ff..00074d8 100644 --- a/gui/Cargo.toml +++ b/gui/Cargo.toml @@ -20,4 +20,7 @@ lazy_static = "1.4.0" base64 = "0.22.1" aes-gcm = "0.10.3" sysinfo = "0.33.0" -rand = "0.8.5" \ No newline at end of file +rand = "0.8.5" +log = "0.4" +simplelog = "0.12" +time = { version = "0.3", features = ["macros"] } \ No newline at end of file diff --git a/gui/src/lib.rs b/gui/src/lib.rs index 6e7d246..c356caf 100644 --- a/gui/src/lib.rs +++ b/gui/src/lib.rs @@ -3,4 +3,5 @@ pub mod config; pub mod app; pub mod ui; pub mod prerun; -pub mod tasks; \ No newline at end of file +pub mod tasks; +pub mod logger; \ No newline at end of file diff --git a/gui/src/logger.rs b/gui/src/logger.rs new file mode 100644 index 0000000..2da83b0 --- /dev/null +++ b/gui/src/logger.rs @@ -0,0 +1,50 @@ +use std::fs::File; +use std::path::PathBuf; +use simplelog::*; +use chrono::Local; +use std::io; +use time::macros::format_description; + +pub struct Logger; + +impl Logger { + pub fn init() -> io::Result<()> { + let home_dir = dirs::home_dir() + .ok_or_else(|| io::Error::new(io::ErrorKind::NotFound, "Home directory not found"))?; + + let log_dir = home_dir.join(".manuscript").join("logs"); + std::fs::create_dir_all(&log_dir)?; + + let log_file_name = format!("manuscript_{}.log", Local::now().format("%Y-%m-%d")); + let log_file_path = log_dir.join(log_file_name); + + println!("log_file_path: {}", log_file_path.to_string_lossy()); + + let config = ConfigBuilder::new() + .set_time_format_custom(format_description!("[year]-[month]-[day] [hour]:[minute]:[second].[subsecond digits:3]")) + .set_thread_level(LevelFilter::Info) + .set_target_level(LevelFilter::Error) + .set_location_level(LevelFilter::Debug) + .build(); + + CombinedLogger::init(vec![ + WriteLogger::new( + LevelFilter::Info, + config.clone(), + File::create(log_file_path)? + ), + ]).map_err(|e| io::Error::new(io::ErrorKind::Other, e))?; + + Ok(()) + } + + pub fn get_log_path() -> io::Result { + let home_dir = dirs::home_dir() + .ok_or_else(|| io::Error::new(io::ErrorKind::NotFound, "Home directory not found"))?; + + let log_dir = home_dir.join(".manuscript").join("logs"); + let log_file_name = format!("manuscript_{}.log", Local::now().format("%Y-%m-%d")); + + Ok(log_dir.join(log_file_name)) + } +} diff --git a/gui/src/main.rs b/gui/src/main.rs index 4738afb..3124c16 100644 --- a/gui/src/main.rs +++ b/gui/src/main.rs @@ -1,9 +1,11 @@ use manuscript_gui::app::App; +use manuscript_gui::logger::Logger; #[tokio::main] async fn main() -> std::io::Result<()> { - env_logger::init(); - + if let Err(e) = Logger::init() { + eprintln!("Failed to initialize logger: {}", e); + } let mut terminal = ratatui::init(); let mut app = App::new().await; let app_result = app.run(&mut terminal); diff --git a/gui/src/tasks/tasks.rs b/gui/src/tasks/tasks.rs index 03859b6..6cceea8 100644 --- a/gui/src/tasks/tasks.rs +++ b/gui/src/tasks/tasks.rs @@ -493,9 +493,12 @@ impl JobManager { name: yaml["name"].as_str().unwrap_or("demo").to_string(), spec_version: yaml["specVersion"].as_str().unwrap_or("v1.0.0").to_string(), parallelism: yaml["parallelism"].as_u64().unwrap_or(1), - db_port: yaml["port"].as_u64().unwrap_or(15432) as u16, - graphql_port: yaml["graphqlPort"].as_u64().unwrap_or(19080) as u16, - job_port: yaml["port"].as_u64().unwrap_or(18080) as u16, + db_port: self.get_available_port(15432, 15439) + .unwrap_or(15432), + graphql_port: self.get_available_port(19080, 19090) + .unwrap_or(19080), + job_port: self.get_available_port(18080, 18090) + .unwrap_or(18080), source: SourceConfig { name: source["name"].as_str().unwrap_or("").to_string(), dataset_type: source["type"].as_str().unwrap_or("dataset").to_string(),