Skip to content

Commit

Permalink
Add log crate and remove eprintln calls
Browse files Browse the repository at this point in the history
  • Loading branch information
fxpineau committed Dec 10, 2024
1 parent c674dff commit 1e17933
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 93 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ exclude = ["crates/wasm"]
[dependencies]
num = "0.4.1"
nom = "7.1.3"
log = "0.4"
quick-error = "2.0.1"
healpix = { package = "cdshealpix", version = "0.7" }
mapproj = "0.3"
Expand Down
1 change: 1 addition & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ bench = false
test = false

[dependencies]
log = "0.4"
moclib = { package = "moc", path = "../.." }
num = "0.4"
structopt = "0.3"
Expand Down
25 changes: 13 additions & 12 deletions crates/cli/src/from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::{
str::{self, FromStr},
};

use log::error;
use structopt::StructOpt;

use healpix::nested::Layer;
Expand Down Expand Up @@ -440,7 +441,7 @@ impl From {
move |line: std::io::Result<String>| match line2cone_params(&separator, line) {
Ok(lonlatrad) => Some(lonlatrad),
Err(e) => {
eprintln!("Error reading or parsing line: {:?}", e);
error!("Error reading or parsing line: {:?}", e);
None
}
};
Expand Down Expand Up @@ -734,7 +735,7 @@ impl From {
let line2moc = move |line: std::io::Result<String>| match line2m(depth, &separator, line) {
Ok(moc) => Some(moc),
Err(e) => {
eprintln!("Error reading or parsing line: {:?}", e);
error!("Error reading or parsing line: {:?}", e);
None
}
};
Expand Down Expand Up @@ -783,7 +784,7 @@ impl From {
let line2pos = move |line: std::io::Result<String>| match line2coos(&separator, line) {
Ok(lonlat) => Some(lonlat),
Err(e) => {
eprintln!("Error reading or parsing line: {:?}", e);
error!("Error reading or parsing line: {:?}", e);
None
}
};
Expand Down Expand Up @@ -873,7 +874,7 @@ impl From {
) {
Ok(uniq_val_dens) => Some(uniq_val_dens),
Err(e) => {
eprintln!("Error reading or parsing line: {:?}", e);
error!("Error reading or parsing line: {:?}", e);
None
}
};
Expand Down Expand Up @@ -903,7 +904,7 @@ impl From {
move |line: std::io::Result<String>| match line2uvd_from_val(&separator, depth, line) {
Ok(uniq_val_dens) => Some(uniq_val_dens),
Err(e) => {
eprintln!("Error reading or parsing line: {:?}", e);
error!("Error reading or parsing line: {:?}", e);
None
}
};
Expand Down Expand Up @@ -998,7 +999,7 @@ impl From {
{
Ok(t) => Some(t),
Err(e) => {
eprintln!("Error reading or parsing line: {:?}", e);
error!("Error reading or parsing line: {:?}", e);
None
}
};
Expand Down Expand Up @@ -1050,7 +1051,7 @@ impl From {
move |line: std::io::Result<String>| match line2tr(&separator, &time, line) {
Ok(trange) => Some(trange),
Err(e) => {
eprintln!("Error reading or parsing line: {:?}", e);
error!("Error reading or parsing line: {:?}", e);
None
}
};
Expand Down Expand Up @@ -1116,7 +1117,7 @@ impl From {
) {
Ok(lonlat) => Some(lonlat),
Err(e) => {
eprintln!("Error reading or parsing line: {:?}", e);
error!("Error reading or parsing line: {:?}", e);
None
}
};
Expand Down Expand Up @@ -1183,7 +1184,7 @@ impl From {
move |line: std::io::Result<String>| match line2trcoos(&separator, &time, layer, line) {
Ok(lonlat) => Some(lonlat),
Err(e) => {
eprintln!("Error reading or parsing line: {:?}", e);
error!("Error reading or parsing line: {:?}", e);
None
}
};
Expand Down Expand Up @@ -1211,11 +1212,11 @@ impl From {
let line2freq = move |line: std::io::Result<String>| match line.map(|s| s.parse::<f64>()) {
Ok(Ok(f)) => Some(f),
Ok(Err(e)) => {
eprintln!("Error reading or parsing line: {:?}", e);
error!("Error reading or parsing line: {:?}", e);
None
}
Err(e) => {
eprintln!("Error reading or parsing line: {:?}", e);
error!("Error reading or parsing line: {:?}", e);
None
}
};
Expand Down Expand Up @@ -1264,7 +1265,7 @@ impl From {
let line2trange = move |line: std::io::Result<String>| match line2tr(&separator, line) {
Ok(trange) => Some(trange),
Err(e) => {
eprintln!("Error reading or parsing line: {:?}", e);
error!("Error reading or parsing line: {:?}", e);
None
}
};
Expand Down
1 change: 1 addition & 0 deletions crates/set/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ bench = false
test = false

[dependencies]
log = "0.4"
moclib = { package = "moc", path = "../.." }
cdshealpix = "0.6.8"
memmap = { package = "memmap2", version = "0.5" }
Expand Down
9 changes: 5 additions & 4 deletions crates/set/src/mk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{

use byteorder::{LittleEndian, WriteBytesExt};
use clap::Parser;
use log::warn;
use memmap::MmapMut;

use moclib::{
Expand Down Expand Up @@ -66,7 +67,7 @@ impl Make {
.enumerate()
.filter_map(|(i, line)| match line.trim().split_once(self.separator) {
None => {
eprintln!(
warn!(
"Line {} ignored. No delimiter '{}' found in {}.",
i, self.separator, line
);
Expand All @@ -75,7 +76,7 @@ impl Make {
Some((id, path)) => match id.trim().parse::<i64>() {
Ok(id) => Some((id, PathBuf::from(path.trim()))),
Err(e) => {
eprintln!(
warn!(
"Line {} ignored. Error parsing identifier '{}': {}",
i, id, e
);
Expand Down Expand Up @@ -145,7 +146,7 @@ impl Make {
// TODO/WARNING: part of code duplicated with 'append.rs' => to be clean (e.g. passing a closure)!
from_byte = match from_fits_file(path.clone()) {
Err(e) => {
eprintln!("MOC id: {}; path: {:?}; ignored. Cause: {:?}", id, path, e);
warn!("MOC id: {}; path: {:?}; ignored. Cause: {:?}", id, path, e);
from_byte
}
Ok(MocIdxType::<BufReader<File>>::U16(MocQtyType::<u16, BufReader<File>>::Hpx(moc))) => {
Expand Down Expand Up @@ -204,7 +205,7 @@ impl Make {
}
}
_ => {
eprintln!(
warn!(
"MOC id: {}; path: {:?}; ignored. Cause: MOC type not supported.",
id, path
);
Expand Down
2 changes: 1 addition & 1 deletion crates/set/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn integration_test() {
.arg("cd resources/tests && ./test.bash")
.output()
.expect("failed to execute process");
// eprintln!("Stderr: {:?}", String::from_utf8(output.stderr));
// println!("Stderr: {:?}", String::from_utf8(output.stderr));
assert!(output.status.success(), "Output status: {}", output.status);
// We double check to be sure that we reach the end of the script
assert_eq!(output.stdout, b"Everything seems OK :)\n");
Expand Down
56 changes: 31 additions & 25 deletions src/deser/ascii.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
use std::io::{self, BufRead, Lines, Write};
use std::marker::PhantomData;
use std::str::FromStr;
use std::{
io::{self, BufRead, Lines, Write},
marker::PhantomData,
str::FromStr,
};

use byteorder::WriteBytesExt;
use log::error;
use quick_error::quick_error;

use nom::branch::alt;
use nom::character::complete::char;
use nom::character::complete::{digit1, multispace0};
use nom::combinator::{cut, map, map_res, opt};
use nom::error::{convert_error, FromExternalError, ParseError, VerboseError};
use nom::multi::many1;
use nom::sequence::{preceded, terminated, tuple};
use nom::IResult;

use crate::elem::{cell::Cell, cellcellrange::CellOrCellRange, cellrange::CellRange};
use crate::elemset::cellcellrange::{CellOrCellRanges, MocCellOrCellRanges};
use crate::idx::Idx;
use crate::moc::{
cellcellrange::CellOrCellRangeMOC, CellOrCellRangeMOCIterator, HasMaxDepth, MOCProperties,
NonOverlapping, ZSorted,
use nom::{
branch::alt,
character::complete::{char, digit1, multispace0},
combinator::{cut, map, map_res, opt},
error::{convert_error, FromExternalError, ParseError, VerboseError},
multi::many1,
sequence::{preceded, terminated, tuple},
IResult,
};
use crate::moc2d::{
cellcellrange::{CellOrCellRangeMOC2, CellOrCellRangeMOC2Elem},
CellOrCellRangeMOC2ElemIt, CellOrCellRangeMOC2Iterator,

use crate::{
elem::{cell::Cell, cellcellrange::CellOrCellRange, cellrange::CellRange},
elemset::cellcellrange::{CellOrCellRanges, MocCellOrCellRanges},
idx::Idx,
moc::{
cellcellrange::CellOrCellRangeMOC, CellOrCellRangeMOCIterator, HasMaxDepth, MOCProperties,
NonOverlapping, ZSorted,
},
moc2d::{
cellcellrange::{CellOrCellRangeMOC2, CellOrCellRangeMOC2Elem},
CellOrCellRangeMOC2ElemIt, CellOrCellRangeMOC2Iterator,
},
qty::MocQty,
};
use crate::qty::MocQty;

quick_error! {
#[derive(Debug)]
Expand Down Expand Up @@ -539,17 +545,17 @@ impl<T: Idx, Q: MocQty<T>, R: BufRead> Iterator for MOCFromAsciiStream<T, Q, R>
return Some(CellOrCellRange::Cell(Cell::new(depth, idx)));
}
}
eprintln!("Error parsing ascii stream at line: {:?}", line);
error!("Error parsing ascii stream at line: {:?}", line);
}
_ => eprintln!(
_ => error!(
"Error parsing ascii stream at line: {:?}. Separator '/' not found.",
line
),
}
}
}
Ok(None) => return None,
Err(e) => eprintln!("Error reading ascii stream: {:?}", e),
Err(e) => error!("Error reading ascii stream: {:?}", e),
}
}
}
Expand Down
71 changes: 39 additions & 32 deletions src/deser/fits/mod.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,45 @@
//! This module deals with MOC serialization/deserialization in the
//! [FITS standard](https://fits.gsfc.nasa.gov/standard40/fits_standard40aa-le.pdf).
use std::io::{BufRead, Cursor, Write};
use std::marker::PhantomData;
use std::ops::Range;
use std::{
io::{BufRead, Cursor, Write},
marker::PhantomData,
ops::Range,
};

use byteorder::BigEndian;
use log::warn;

use crate::deser::fits::{
common::{
check_keyword_and_parse_uint_val, check_keyword_and_val, consume_primary_hdu,
next_36_chunks_of_80_bytes, write_primary_hdu, write_uint_mandatory_keyword_record,
use crate::{
deser::fits::{
common::{
check_keyword_and_parse_uint_val, check_keyword_and_val, consume_primary_hdu,
next_36_chunks_of_80_bytes, write_primary_hdu, write_uint_mandatory_keyword_record,
},
error::FitsError,
keywords::{
CoordSys, FitsCard, MocDim, MocId, MocKeywords, MocKeywordsMap, MocOrdF, MocOrdS, MocOrdT,
MocOrder, MocTool, MocVers, Ordering, TForm1, TType1, TimeSys,
},
},
error::FitsError,
keywords::{
CoordSys, FitsCard, MocDim, MocId, MocKeywords, MocKeywordsMap, MocOrdF, MocOrdS, MocOrdT,
MocOrder, MocTool, MocVers, Ordering, TForm1, TType1, TimeSys,
elem::cell::Cell,
elemset::{
cell::{Cells, MocCells},
range::MocRanges,
},
idx::Idx,
moc::{
cell::CellMOC,
range::{op::convert::convert_to_u64, RangeMOC, RangeMocIter},
CellMOCIntoIterator, CellMOCIterator, HasMaxDepth, MOCProperties, NonOverlapping,
RangeMOCIterator, ZSorted,
},
moc2d::{
range::{RangeMOC2, RangeMOC2Elem},
HasTwoMaxDepth, MOC2Properties, RangeMOC2ElemIt, RangeMOC2IntoIterator, RangeMOC2Iterator,
},
qty::{Frequency, Hpx, MocQty, MocableQty, Time},
};
use crate::elem::cell::Cell;
use crate::elemset::{
cell::{Cells, MocCells},
range::MocRanges,
};
use crate::idx::Idx;
use crate::moc::range::op::convert::convert_to_u64;
use crate::moc::{
cell::CellMOC,
range::{RangeMOC, RangeMocIter},
CellMOCIntoIterator, CellMOCIterator, HasMaxDepth, MOCProperties, NonOverlapping,
RangeMOCIterator, ZSorted,
};
use crate::moc2d::{
range::{RangeMOC2, RangeMOC2Elem},
HasTwoMaxDepth, MOC2Properties, RangeMOC2ElemIt, RangeMOC2IntoIterator, RangeMOC2Iterator,
};
use crate::qty::{Frequency, Hpx, MocQty, MocableQty, Time};

pub mod common;
pub mod error;
Expand Down Expand Up @@ -594,7 +598,10 @@ pub fn from_fits_ivoa_custom<R: BufRead>(
if let Some(previous_mkw) = moc_kws.insert(mkw?) {
// A FITS keyword MUST BE uniq (I may be more relax here, taking the last one and not complaining)
// return Err(FitsError::MultipleKeyword(previous_mkw.keyword_str().to_string()))
eprintln!("WARNING: Keyword '{}' found more than once in a same HDU! We use the first occurrence.", previous_mkw.keyword_str());
warn!(
"Keyword '{}' found more than once in a same HDU! We use the first occurrence.",
previous_mkw.keyword_str()
);
moc_kws.insert(previous_mkw);
}
// else keyword added without error
Expand Down Expand Up @@ -993,8 +1000,8 @@ where
R: BufRead,
{
if depth_max > Hpx::<T>::MAX_DEPTH {
eprintln!(
"WARNING: Wrong depth_max {}. Reset to {}",
warn!(
"Wrong depth_max {}. Reset to {}",
depth_max,
Hpx::<T>::MAX_DEPTH
);
Expand Down
6 changes: 5 additions & 1 deletion src/deser/fits/multiordermap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{
};

use byteorder::{BigEndian, ReadBytesExt};
use log::warn;

use crate::{
deser::{
Expand Down Expand Up @@ -215,7 +216,10 @@ impl<R: BufRead> MultiOrderMapIterator<R> {
if let Some(previous_mkw) = moc_kws.insert(mkw?) {
// A FITS keyword MUST BE uniq (I may be more relax here, taking the last one and not complaining)
// return Err(FitsError::MultipleKeyword(previous_mkw.keyword_str().to_string()))
eprintln!("WARNING: Keyword '{}' found more than once in a same HDU! We use the first occurrence.", previous_mkw.keyword_str());
warn!(
"Keyword '{}' found more than once in a same HDU! We use the first occurrence.",
previous_mkw.keyword_str()
);
moc_kws.insert(previous_mkw);
}
// else keyword added without error
Expand Down
Loading

0 comments on commit 1e17933

Please sign in to comment.