deactivate println!(), use logging via tracing crate

Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
2020-07-03 03:31:46 +02:00
parent 9c819af548
commit 8c5d540a74
6 changed files with 36 additions and 34 deletions

View File

@@ -66,7 +66,7 @@ fn export(p: &mut String, lang: &String) -> Result<usize, Box<dyn Error>> {
let dt_end: DateTime<Local> = Local::now();
let duration = dt_end.signed_duration_since(dt_start);
println!("Duration: {:#?}", duration);
//println!("Duration: {:#?}", duration);
trace!(target: "csv-test", record_count = ?count, duration = ?duration);
trace!(target: "csv-test", process = "csv-import", state = "finished");
@@ -97,7 +97,7 @@ fn import(p: &mut String, data_list: &mut PolicyDataList,
// must be a readable file
trace!(target: "csv-test", path = ?path);
let valid = path.is_file();
println!("is_file: {}", valid);
//println!("is_file: {}", valid);
//if let Some(res) = valid
assert_eq!(path.is_file(), true);

View File

@@ -77,25 +77,25 @@ impl PolicyCheckState {
// importing policy code elements from csv-file
let policy_list = PolicyList::new("Allianz Versicherungsnummen-List");
println!("Policy List {:?} ", policy_list.name);
//println!("Policy List {:?} ", policy_list.name);
let mut policy_data = PolicyDataList::new("Allianz-Import latest");
println!("Policy Data List {:?} ", policy_data.name);
//println!("Policy Data List {:?} ", policy_data.name);
let mut policy_numbers : HashMap<usize, PolicyCode> = HashMap::new();
// Wip: use cli parameter stored in viperus ...
//let mut csv_import_path = v.get::<String>("import_file").unwrap();
let mut csv_import_path = String::from("POLLFNR_WOECHENTLICH.txt");
println!("Importing from: {:?}", csv_import_path);
//println!("Importing from: {:?}", csv_import_path);
match import(&mut csv_import_path, &mut policy_data,
&mut policy_numbers, &lang) {
Ok(count) => {
self.policy_data_count = count;
println!("Imported {:?} records", self.policy_data_count);
//println!("Imported {:?} records", self.policy_data_count);
}
Err(err) => {
println!("error running CSV-Import: {}", err);
//println!("error running CSV-Import: {}", err);
process::exit(1);
}
};
@@ -108,14 +108,14 @@ impl PolicyCheckState {
pub fn clear_entry(&mut self, text_box: Entity, ctx: &mut Context<'_>) {
let mut text_box = TextBox::get(ctx.get_widget(text_box));
let text = text_box.text_mut();
println!("reset {}", text);
//println!("reset {}", text);
}
/// Open menu.
pub fn open_menu(&mut self, text_block: Entity, ctx: &mut Context<'_>) {
let mut text_block = TextBlock::get(ctx.get_widget(text_block));
let text = text_block.text_mut();
println!("Menu text: {}", text);
//println!("Menu text: {}", text);
}
fn parse_entry(&mut self, policy_check_policy_number: Entity,
@@ -129,12 +129,12 @@ impl PolicyCheckState {
// DION VERS POLLFNR
// 1 AS 1515735810
if policy_number_length == 10 {
let mut label_wrapper : TextBlockCtx<'_> = text_block(ctx.child("policy_check_label_result"));
let string_label = "Prüfungsergebnis:".to_string();
// needs to be an integer
match policy_string.parse::<usize>() {
Ok(p) => {
println!(" ... verify policy Number {:?}", p);
let mut label_wrapper : TextBlockCtx<'_> = text_block(ctx.child("policy_check_label_result"));
let string_label = "Prüfungsergebnis:".to_string();
//println!(" ... verify policy Number {:?}", p);
label_wrapper.set_text(string_label);
label_wrapper.set_visibility(Visibility::Visible);
label_wrapper.set_enabled(true);
@@ -151,11 +151,8 @@ impl PolicyCheckState {
result_wrapper.set_text(string_result);
}
_ => {
//let res = t!("policy.validation.failed", lang);
//println!("{:?}", res);
trace!(target: "advotracker", state = "failed",
policy_number = ?p);
println!("Noop! Number isn't valid!");
result_wrapper.set_enabled(true);
result_wrapper.set_text("noop, ungültig!");
}
@@ -163,15 +160,16 @@ impl PolicyCheckState {
},
Err(e) => {
trace!(target: "advotracker", state = "error", error_type = "invalid type");
println!("invalid: {}", e);
// Feedback
println!("Please enter an integer!");
let mut result_wrapper: TextBlockCtx<'_> = text_block(ctx.child("policy_check_result"));
result_wrapper.set_enabled(true);
result_wrapper.set_text("bitte nur Nummern erfassen!");
}
}
}
if policy_number_length < 10 {
println!("Policy number is to short!");
//println!("Policy number is to short!");
let mut text_block_wrapper: TextBlockCtx<'_> = text_block(ctx.child("policy_check_result"));
text_block_wrapper.set_enabled(true);
text_block_wrapper.set_text("zu kurz!");
@@ -179,7 +177,7 @@ impl PolicyCheckState {
//ctx.child(ID_POLICY_CHECK_POLICY_NUMBER).set("text", String::from(""));
}
if policy_number_length > 10 {
println!("Policy number is to big!");
//println!("Policy number is to big!");
let mut text_block_wrapper: TextBlockCtx<'_> = text_block(ctx.child("policy_check_result"));
text_block_wrapper.set_enabled(true);
text_block_wrapper.set_text("zu lang!");
@@ -270,7 +268,7 @@ impl State for PolicyCheckState {
}
}
} else {
println!("Already imported {} records.", self.policy_data_count);
//println!("Already imported {} records.", self.policy_data_count);
trace!(target: "advotracker",
hashmap_status = "consume",
hashmap_entries = ?self.policy_data_count);

View File

@@ -64,11 +64,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// initialize the tracing subsystem
// a drop in replacement for classical logging
// reference: https://tokio.rs/blog/2019-08-tracing/
let span = tracing::span!(Level::TRACE, "csv-test");
let span = tracing::span!(Level::TRACE, "advotracker");
let _enter = span.enter();
let subscriber = fmt::Subscriber::builder()
.with_env_filter("trace")
//.with_max_level(tracing::Level::DEBUG)
//.with_env_filter("trace")
.with_max_level(tracing::Level::INFO)
.finish();
tracing::subscriber::with_default(subscriber, || {

View File

@@ -18,12 +18,12 @@ use viperus::Viperus;
pub fn parse_args(viperus: &mut Viperus) -> Result<(), Box<dyn std::error::Error>> {
if cfg!(feature = "global") {
trace!(target: "Viperus", "Viperus feature 'global' enabled.");
println!("Lasy static: 'VIPERUS' is accessible globaly");
//println!("Lasy static: 'VIPERUS' is accessible globaly");
}
if cfg!(feature = "fmt-clap") {
trace!(target: "Viperus", "Viperus feature 'fmt-clap' enabled.");
println!("Using feature fmt-clap");
//println!("Using feature fmt-clap");
}
// preset default key/value pairs (lowest priority)
@@ -144,10 +144,10 @@ SMR Unerledigt: 089 92529 60222")
// respect dotenv environment (e.g for testing)
// -> overwrites the preset default values
println!(
"RUST_LOG={}",
dotenv::var("RUST_LOG").unwrap_or_else(|_| String::from("None"))
);
//println!(
// "RUST_LOG={}",
// dotenv::var("RUST_LOG").unwrap_or_else(|_| String::from("None"))
//);
// enable caching and automatic update of environment values
viperus.cache(true);

View File

@@ -89,10 +89,15 @@ pub fn import(p: &mut String, data_list: &mut PolicyDataList,
for p in &my_policy_numbers {
match policy_numbers.get(&p) {
Some(policy_code) => {
println!("Test: Policy-Number {:?} => Policy-Type {:?}, as expected!",
p, policy_code);
//println!("Test: Policy-Number {:?} => Policy-Type {:?}, as expected!",
// p, policy_code);
trace!(target: "advotrackerd",
record_test = ?p, status = "success", policy_typ = ?policy_code);
},
_ => println!("Test: Policy-Number {:?} => not valid, can't dereference the Policy-Type as expected", p),
_ => {
//println!("Test: Policy-Number {:?} => not valid, can't dereference the Policy-Type as expected", p),
trace!(target: "advotrackerd", record_fail_test = ?p, status = "failed");
}
}
}

View File

@@ -249,7 +249,6 @@ impl Template for PolicyCheckView {
.text("")
.on_activate(move |ctx, entity| {
// Entity is entered/activated via Mouse/Keyboard
println!("activation finished!");
ctx.get_mut::<PolicyCheckState>(id)
.action(Action::ParseEntry(entity));
})