Skip to content

Commit

Permalink
Merge pull request #14 from Skynoodle/feature/log
Browse files Browse the repository at this point in the history
Move diagnostic printlns into feature-flagged logging
  • Loading branch information
Twinklebear authored Aug 13, 2019
2 parents 57fb70d + 12462c0 commit cc7b12c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ exclude = [
".travis.yml",
]

[dependencies]
log = { version = "0.4.8", optional = true }
27 changes: 16 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,10 +522,11 @@ fn export_faces(pos: &[f32],
pub fn load_obj(file_name: &Path) -> LoadResult {
let file = match File::open(file_name) {
Ok(f) => f,
Err(e) => {
println!("tobj::load_obj - failed to open {:?} due to {}",
Err(_e) => {
#[cfg(feature = "log")]
log::error!("load_obj - failed to open {:?} due to {}",
file_name,
e);
_e);
return Err(LoadError::OpenFileFailed);
}
};
Expand All @@ -547,10 +548,11 @@ pub fn load_obj(file_name: &Path) -> LoadResult {
pub fn load_mtl(file_name: &Path) -> MTLLoadResult {
let file = match File::open(file_name) {
Ok(f) => f,
Err(e) => {
println!("tobj::load_mtl - failed to open {:?} due to {}",
Err(_e) => {
#[cfg(feature = "log")]
log::error!("load_mtl - failed to open {:?} due to {}",
file_name,
e);
_e);
return Err(LoadError::OpenFileFailed);
}
};
Expand Down Expand Up @@ -618,8 +620,9 @@ pub fn load_obj_buf<B, ML>(reader: &mut B, material_loader: ML) -> LoadResult
for line in reader.lines() {
let (line, mut words) = match line {
Ok(ref line) => (&line[..], line[..].split_whitespace()),
Err(e) => {
println!("tobj::load_obj - failed to read line due to {}", e);
Err(_e) => {
#[cfg(feature = "log")]
log::error!("load_obj - failed to read line due to {}", _e);
return Err(LoadError::ReadError);
}
};
Expand Down Expand Up @@ -702,7 +705,8 @@ pub fn load_obj_buf<B, ML>(reader: &mut B, material_loader: ML) -> LoadResult
tmp_faces.clear();
}
if new_mat.is_none() {
println!("Warning: Object {} refers to unfound material: {}",
#[cfg(feature = "log")]
log::warn!("Object {} refers to unfound material: {}",
name,
mat_name);
}
Expand Down Expand Up @@ -737,8 +741,9 @@ pub fn load_mtl_buf<B: BufRead>(reader: &mut B) -> MTLLoadResult {
for line in reader.lines() {
let (line, mut words) = match line {
Ok(ref line) => (line.trim(), line[..].split_whitespace()),
Err(e) => {
println!("tobj::load_obj - failed to read line due to {}", e);
Err(_e) => {
#[cfg(feature = "log")]
log::error!("load_obj - failed to read line due to {}", _e);
return Err(LoadError::ReadError);
}
};
Expand Down

0 comments on commit cc7b12c

Please sign in to comment.