diff options
author | GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> | 2023-03-21 09:31:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-21 08:31:36 +0000 |
commit | 36fdc302bef162d213d6a026c99614673b24a069 (patch) | |
tree | cadbdda49542ddf5234040206676a186ebe9b440 /src-tauri/src | |
parent | 25791906cc8c81368af5718f8ec6ee8b4f428b31 (diff) | |
download | FlightCore-36fdc302bef162d213d6a026c99614673b24a069.tar.gz FlightCore-36fdc302bef162d213d6a026c99614673b24a069.zip |
feat: Proper logging (#223)
* feat: Initial setup of sentry logging
* refactor: Replace some println with log call
Not replacing all cause too large diff
Diffstat (limited to 'src-tauri/src')
-rw-r--r-- | src-tauri/src/github/release_notes.rs | 6 | ||||
-rw-r--r-- | src-tauri/src/lib.rs | 13 | ||||
-rw-r--r-- | src-tauri/src/main.rs | 15 | ||||
-rw-r--r-- | src-tauri/src/northstar/mod.rs | 5 |
4 files changed, 20 insertions, 19 deletions
diff --git a/src-tauri/src/github/release_notes.rs b/src-tauri/src/github/release_notes.rs index b59358ec..e8e5c1fa 100644 --- a/src-tauri/src/github/release_notes.rs +++ b/src-tauri/src/github/release_notes.rs @@ -20,7 +20,7 @@ pub struct FlightCoreVersion { // Fetches repo release API and returns response as string pub async fn fetch_github_releases_api(url: &str) -> Result<String, String> { - println!("Fetching releases notes from GitHub API"); + log::info!("Fetching releases notes from GitHub API"); let client = reqwest::Client::new(); let res = client @@ -40,13 +40,13 @@ pub async fn fetch_github_releases_api(url: &str) -> Result<String, String> { #[tauri::command] pub async fn get_newest_flightcore_version() -> Result<FlightCoreVersion, String> { // Get newest version number from GitHub API - println!("Checking GitHub API"); + log::info!("Checking GitHub API"); let url = "https://api.github.com/repos/R2NorthstarTools/FlightCore/releases/latest"; let res = fetch_github_releases_api(url).await?; let flightcore_version: FlightCoreVersion = serde_json::from_str(&res).expect("JSON was not well-formatted"); - println!("Done checking GitHub API"); + log::info!("Done checking GitHub API"); Ok(flightcore_version) } diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 050b4238..2e0a0250 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1,7 +1,6 @@ use std::env; use anyhow::{anyhow, Context, Result}; -use sentry::{add_breadcrumb, Breadcrumb, Level}; mod northstar; @@ -61,7 +60,7 @@ pub fn check_mod_version_number(path_to_mod_folder: String) -> Result<String, an None => return Err(anyhow!("No version number found")), }; - println!("{}", mod_version_number); + log::info!("{}", mod_version_number); Ok(mod_version_number.to_string()) } @@ -132,7 +131,7 @@ pub fn find_game_install_location() -> Result<GameInstall, String> { pub fn check_is_valid_game_path(game_install_path: &str) -> Result<(), String> { let path_to_titanfall2_exe = format!("{}/Titanfall2.exe", game_install_path); let is_correct_game_path = std::path::Path::new(&path_to_titanfall2_exe).exists(); - println!("Titanfall2.exe exists in path? {}", is_correct_game_path); + log::info!("Titanfall2.exe exists in path? {}", is_correct_game_path); // Exit early if wrong game path if !is_correct_game_path { @@ -231,13 +230,7 @@ pub async fn install_northstar( .ok_or_else(|| panic!("Couldn't find Northstar on thunderstore???")) .unwrap(); - // Breadcrumb for sentry to debug crash - add_breadcrumb(Breadcrumb { - // category: Some("auth".into()), - message: Some(format!("Install path \"{}\"", game_path)), - level: Level::Info, - ..Default::default() - }); + log::info!("Install path \"{}\"", game_path); match do_install( nmod.versions.get(&nmod.latest).unwrap(), diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 50e439c8..0733d5a0 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -45,6 +45,14 @@ use tokio::time::sleep; struct Counter(Arc<Mutex<i32>>); fn main() { + // Setup logger + let mut log_builder = pretty_env_logger::formatted_builder(); + log_builder.parse_filters("info"); + let logger = sentry_log::SentryLogger::with_dest(log_builder.build()); + + log::set_boxed_logger(Box::new(logger)).unwrap(); + log::set_max_level(log::LevelFilter::Info); + // Only enable Sentry crash logs on release #[cfg(not(debug_assertions))] let _guard = sentry::init(( @@ -222,10 +230,10 @@ async fn check_is_northstar_outdated( let version_number = convert_release_candidate_number(version_number); if version_number != nmod.latest { - println!("Installed Northstar version outdated"); + log::info!("Installed Northstar version outdated"); Ok(true) } else { - println!("Installed Northstar version up-to-date"); + log::info!("Installed Northstar version up-to-date"); Ok(false) } } @@ -353,7 +361,8 @@ async fn get_server_player_count() -> Result<(i32, usize), String> { // Sum up player count let total_player_count: i32 = ns_servers.iter().map(|server| server.player_count).sum(); - dbg!((total_player_count, server_count)); + log::info!("total_player_count: {}", total_player_count); + log::info!("server_count: {}", server_count); Ok((total_player_count, server_count)) } diff --git a/src-tauri/src/northstar/mod.rs b/src-tauri/src/northstar/mod.rs index a043632c..f3f8cde3 100644 --- a/src-tauri/src/northstar/mod.rs +++ b/src-tauri/src/northstar/mod.rs @@ -6,8 +6,7 @@ use anyhow::anyhow; /// Returns the current Northstar version number as a string pub fn get_northstar_version_number(game_path: String) -> Result<String, anyhow::Error> { - println!("{}", game_path); - // println!("{:?}", install_type); + log::info!("{}", game_path); // TODO: // Check if NorthstarLauncher.exe exists and check its version number @@ -33,7 +32,7 @@ pub fn get_northstar_version_number(game_path: String) -> Result<String, anyhow: return Err(anyhow!("Found version number mismatch")); } } - println!("All mods same version"); + log::info!("All mods same version"); Ok(initial_version_number) } |