From bb6bc07906358fd3607402d87b4041956f316ebc Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Wed, 28 Nov 2018 16:55:56 +0100 Subject: [PATCH] Use log / stderrlog --- Cargo.toml | 3 ++- src/lib.rs | 5 ++++- src/model/mod.rs | 12 ++++++------ src/parser/mod.rs | 2 +- src/parser/obj.rs | 2 +- src/programs/viewer.rs | 36 +++++++++++++++++++++++------------- 6 files changed, 37 insertions(+), 23 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d1cd21e..8242a72 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,13 +4,14 @@ version = "0.1.0" authors = ["Thomas Forgione "] [dependencies] +log = "0.4" +stderrlog = "0.4.1" num = "0.1.42" glium = "0.22.0" image = "0.19.0" byteorder = "1.2.3" clap = "2.31.2" nalgebra = "0.15.3" -verbose-log = { git = "https://gitea.tforgione.fr/dash-3d/verbose-log" } [[bin]] name = "3d-viewer" diff --git a/src/lib.rs b/src/lib.rs index bf9b1af..74f76b8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,11 +2,14 @@ #![warn(missing_docs)] +#[macro_use] +extern crate log; +extern crate stderrlog; + extern crate num; extern crate image; extern crate nalgebra; -#[macro_use] extern crate verbose_log; #[macro_use] extern crate glium; pub mod math; diff --git a/src/model/mod.rs b/src/model/mod.rs index 118c4d4..b561f30 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -145,7 +145,7 @@ impl Model { for (name, material) in &other.materials { let entry = self.materials.entry(name.clone()); if let Entry::Occupied(_) = entry { - eprintln!("Warning: materials merged but sharing the same name"); + warn!("Materials merged but sharing the same name"); // Return error } else { entry.or_insert(material.clone()); @@ -156,7 +156,7 @@ impl Model { for (name, texture) in &other.textures { let entry = self.textures.entry(name.clone()); if let Entry::Occupied(_) = entry { - eprintln!("Warning: textures merged but sharing the same name"); + warn!("Textures merged but sharing the same name"); // return Error; } else { entry.or_insert(texture.clone()); @@ -172,7 +172,7 @@ impl Model { for (name, material) in other.materials { let entry = self.materials.entry(name); if let Entry::Occupied(_) = entry { - eprintln!("Warning: materials merged but sharing the same name"); + warn!("Materials merged but sharing the same name"); // Return error } else { entry.or_insert(material); @@ -183,7 +183,7 @@ impl Model { for (name, texture) in other.textures { let entry = self.textures.entry(name); if let Entry::Occupied(_) = entry { - eprintln!("Warning: textures merged but sharing the same name"); + warn!("Textures merged but sharing the same name"); // return Error; } else { entry.or_insert(texture); @@ -235,7 +235,7 @@ impl Model { for (name, material) in other.materials { let entry = self.materials.entry(name); if let Entry::Occupied(_) = entry { - eprintln!("Warning: materials merged but sharing the same name"); + warn!("Materials merged but sharing the same name"); // Return error } else { entry.or_insert(material); @@ -246,7 +246,7 @@ impl Model { for (name, texture) in other.textures { let entry = self.textures.entry(name); if let Entry::Occupied(_) = entry { - eprintln!("Warning: textures merged but sharing the same name"); + warn!("Textures merged but sharing the same name"); // return Error; } else { entry.or_insert(texture); diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 41729ff..097970f 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -204,7 +204,7 @@ pub trait Parser { /// Parses a file and adds its content to an already existing model. fn parse_into_model(&mut self, model: &mut Model, reader: R, path: &str) -> Result<(), ParserError> { - logln!("Parsing {}...", path); + info!("Parsing {}...", path); self.priv_parse_into_model(model, reader, path) } diff --git a/src/parser/obj.rs b/src/parser/obj.rs index f8dfd10..4f66f80 100644 --- a/src/parser/obj.rs +++ b/src/parser/obj.rs @@ -82,7 +82,7 @@ impl ObjParser { ))) } else { let values = parse_values(line_number, line, path, 3)?; - logln!("Warning: expected 2 coordinates, but received 3, ignoring the last one..."); + warn!("Warning: expected 2 coordinates, but received 3, ignoring the last one..."); Ok(Element::TextureCoordinate(Vector2::::new( values[0], values[1], diff --git a/src/programs/viewer.rs b/src/programs/viewer.rs index fae6136..44a3659 100644 --- a/src/programs/viewer.rs +++ b/src/programs/viewer.rs @@ -1,7 +1,8 @@ +#[macro_use] +extern crate log; +extern crate stderrlog; extern crate clap; extern crate glium; -#[macro_use] -extern crate verbose_log; extern crate model_converter; use std::process::exit; @@ -52,11 +53,16 @@ fn main() { .arg(Arg::with_name("verbose") .short("v") .long("verbose") + .multiple(true) .help("Shows logs during the parsing of the model")) .get_matches(); // Set verbose flag - verbose_log::set(matches.occurrences_of("verbose") > 0); + stderrlog::new() + .module(module_path!()) + .verbosity(matches.occurrences_of("verbose") as usize) + .init() + .expect("Couldn't initialize logger"); let mut capture_count = 0; @@ -69,6 +75,9 @@ fn main() { let mut models = vec![]; for input in matches.values_of("input").unwrap() { + + info!("Parsing model {}", input); + match parse_file(&input) { Ok(model) => { if model.vertices.len() > 0 { @@ -77,7 +86,7 @@ fn main() { models.push((input.to_owned(), model)) }, Err(e) => { - eprintln!("Error while parsing file: {}", e); + error!("Error while parsing file: {}", e); exit(1); }, } @@ -95,24 +104,25 @@ fn main() { let mut duration; for (name, mut model) in models { - log!("Scaling model {}...", name); + info!("Scaling model {}...", name); model.center_and_scale_from_box(&bbox); - log!("\nBuilding textures for model {}...", name); + info!("Building textures for model {}...", name); before = Instant::now(); model.build_textures(&renderer); duration = Instant::now().duration_since(before); - log!(" done in {}ms.\nBuilding vertex buffers for model {}...", - as_millis(duration) ,name); + info!("Done in {}ms.", as_millis(duration)); + info!("Building vertex buffers for model {}...", name); before = Instant::now(); model.build_vertex_buffers(&renderer); duration = Instant::now().duration_since(before); scene.emplace(model); - logln!(" done in {}ms.\nFinished", as_millis(duration)); + info!("Done in {}ms.", as_millis(duration)); + info!("Finished"); } let mut closed = false; @@ -174,13 +184,13 @@ fn main() { }, .. }, .. } => { - println!("Camera:"); + trace!("Camera:"); - println!("\tPosition: ({}, {}, {})", + trace!("\tPosition: ({}, {}, {})", camera.position.x(), camera.position.y(), camera.position.z()); - println!("\tTarget: ({}, {}, {})", + trace!("\tTarget: ({}, {}, {})", camera.target.x(), camera.target.y(), camera.target.z()); - println!("\tUp: ({}, {}, {})", + trace!("\tUp: ({}, {}, {})", camera.up.x(), camera.up.y(), camera.up.z()); },