deactivate println!(), use logging via tracing crate
Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
@@ -66,7 +66,7 @@ fn export(p: &mut String, lang: &String) -> Result<usize, Box<dyn Error>> {
|
|||||||
|
|
||||||
let dt_end: DateTime<Local> = Local::now();
|
let dt_end: DateTime<Local> = Local::now();
|
||||||
let duration = dt_end.signed_duration_since(dt_start);
|
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", record_count = ?count, duration = ?duration);
|
||||||
trace!(target: "csv-test", process = "csv-import", state = "finished");
|
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
|
// must be a readable file
|
||||||
trace!(target: "csv-test", path = ?path);
|
trace!(target: "csv-test", path = ?path);
|
||||||
let valid = path.is_file();
|
let valid = path.is_file();
|
||||||
println!("is_file: {}", valid);
|
//println!("is_file: {}", valid);
|
||||||
|
|
||||||
//if let Some(res) = valid
|
//if let Some(res) = valid
|
||||||
assert_eq!(path.is_file(), true);
|
assert_eq!(path.is_file(), true);
|
||||||
|
|||||||
@@ -77,25 +77,25 @@ impl PolicyCheckState {
|
|||||||
|
|
||||||
// importing policy code elements from csv-file
|
// importing policy code elements from csv-file
|
||||||
let policy_list = PolicyList::new("Allianz Versicherungsnummen-List");
|
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");
|
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();
|
let mut policy_numbers : HashMap<usize, PolicyCode> = HashMap::new();
|
||||||
|
|
||||||
// Wip: use cli parameter stored in viperus ...
|
// Wip: use cli parameter stored in viperus ...
|
||||||
//let mut csv_import_path = v.get::<String>("import_file").unwrap();
|
//let mut csv_import_path = v.get::<String>("import_file").unwrap();
|
||||||
let mut csv_import_path = String::from("POLLFNR_WOECHENTLICH.txt");
|
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,
|
match import(&mut csv_import_path, &mut policy_data,
|
||||||
&mut policy_numbers, &lang) {
|
&mut policy_numbers, &lang) {
|
||||||
Ok(count) => {
|
Ok(count) => {
|
||||||
self.policy_data_count = count;
|
self.policy_data_count = count;
|
||||||
println!("Imported {:?} records", self.policy_data_count);
|
//println!("Imported {:?} records", self.policy_data_count);
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
println!("error running CSV-Import: {}", err);
|
//println!("error running CSV-Import: {}", err);
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -108,14 +108,14 @@ impl PolicyCheckState {
|
|||||||
pub fn clear_entry(&mut self, text_box: Entity, ctx: &mut Context<'_>) {
|
pub fn clear_entry(&mut self, text_box: Entity, ctx: &mut Context<'_>) {
|
||||||
let mut text_box = TextBox::get(ctx.get_widget(text_box));
|
let mut text_box = TextBox::get(ctx.get_widget(text_box));
|
||||||
let text = text_box.text_mut();
|
let text = text_box.text_mut();
|
||||||
println!("reset {}", text);
|
//println!("reset {}", text);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Open menu.
|
/// Open menu.
|
||||||
pub fn open_menu(&mut self, text_block: Entity, ctx: &mut Context<'_>) {
|
pub fn open_menu(&mut self, text_block: Entity, ctx: &mut Context<'_>) {
|
||||||
let mut text_block = TextBlock::get(ctx.get_widget(text_block));
|
let mut text_block = TextBlock::get(ctx.get_widget(text_block));
|
||||||
let text = text_block.text_mut();
|
let text = text_block.text_mut();
|
||||||
println!("Menu text: {}", text);
|
//println!("Menu text: {}", text);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_entry(&mut self, policy_check_policy_number: Entity,
|
fn parse_entry(&mut self, policy_check_policy_number: Entity,
|
||||||
@@ -129,12 +129,12 @@ impl PolicyCheckState {
|
|||||||
// DION VERS POLLFNR
|
// DION VERS POLLFNR
|
||||||
// 1 AS 1515735810
|
// 1 AS 1515735810
|
||||||
if policy_number_length == 10 {
|
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
|
// needs to be an integer
|
||||||
match policy_string.parse::<usize>() {
|
match policy_string.parse::<usize>() {
|
||||||
Ok(p) => {
|
Ok(p) => {
|
||||||
println!(" ... verify policy Number {:?}", 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();
|
|
||||||
label_wrapper.set_text(string_label);
|
label_wrapper.set_text(string_label);
|
||||||
label_wrapper.set_visibility(Visibility::Visible);
|
label_wrapper.set_visibility(Visibility::Visible);
|
||||||
label_wrapper.set_enabled(true);
|
label_wrapper.set_enabled(true);
|
||||||
@@ -151,11 +151,8 @@ impl PolicyCheckState {
|
|||||||
result_wrapper.set_text(string_result);
|
result_wrapper.set_text(string_result);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
//let res = t!("policy.validation.failed", lang);
|
|
||||||
//println!("{:?}", res);
|
|
||||||
trace!(target: "advotracker", state = "failed",
|
trace!(target: "advotracker", state = "failed",
|
||||||
policy_number = ?p);
|
policy_number = ?p);
|
||||||
println!("Noop! Number isn't valid!");
|
|
||||||
result_wrapper.set_enabled(true);
|
result_wrapper.set_enabled(true);
|
||||||
result_wrapper.set_text("noop, ungültig!");
|
result_wrapper.set_text("noop, ungültig!");
|
||||||
}
|
}
|
||||||
@@ -163,15 +160,16 @@ impl PolicyCheckState {
|
|||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
trace!(target: "advotracker", state = "error", error_type = "invalid type");
|
trace!(target: "advotracker", state = "error", error_type = "invalid type");
|
||||||
println!("invalid: {}", e);
|
|
||||||
// Feedback
|
// 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 {
|
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"));
|
let mut text_block_wrapper: TextBlockCtx<'_> = text_block(ctx.child("policy_check_result"));
|
||||||
text_block_wrapper.set_enabled(true);
|
text_block_wrapper.set_enabled(true);
|
||||||
text_block_wrapper.set_text("zu kurz!");
|
text_block_wrapper.set_text("zu kurz!");
|
||||||
@@ -179,7 +177,7 @@ impl PolicyCheckState {
|
|||||||
//ctx.child(ID_POLICY_CHECK_POLICY_NUMBER).set("text", String::from(""));
|
//ctx.child(ID_POLICY_CHECK_POLICY_NUMBER).set("text", String::from(""));
|
||||||
}
|
}
|
||||||
if policy_number_length > 10 {
|
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"));
|
let mut text_block_wrapper: TextBlockCtx<'_> = text_block(ctx.child("policy_check_result"));
|
||||||
text_block_wrapper.set_enabled(true);
|
text_block_wrapper.set_enabled(true);
|
||||||
text_block_wrapper.set_text("zu lang!");
|
text_block_wrapper.set_text("zu lang!");
|
||||||
@@ -270,7 +268,7 @@ impl State for PolicyCheckState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
println!("Already imported {} records.", self.policy_data_count);
|
//println!("Already imported {} records.", self.policy_data_count);
|
||||||
trace!(target: "advotracker",
|
trace!(target: "advotracker",
|
||||||
hashmap_status = "consume",
|
hashmap_status = "consume",
|
||||||
hashmap_entries = ?self.policy_data_count);
|
hashmap_entries = ?self.policy_data_count);
|
||||||
|
|||||||
@@ -64,11 +64,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// initialize the tracing subsystem
|
// initialize the tracing subsystem
|
||||||
// a drop in replacement for classical logging
|
// a drop in replacement for classical logging
|
||||||
// reference: https://tokio.rs/blog/2019-08-tracing/
|
// 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 _enter = span.enter();
|
||||||
let subscriber = fmt::Subscriber::builder()
|
let subscriber = fmt::Subscriber::builder()
|
||||||
.with_env_filter("trace")
|
//.with_env_filter("trace")
|
||||||
//.with_max_level(tracing::Level::DEBUG)
|
.with_max_level(tracing::Level::INFO)
|
||||||
.finish();
|
.finish();
|
||||||
|
|
||||||
tracing::subscriber::with_default(subscriber, || {
|
tracing::subscriber::with_default(subscriber, || {
|
||||||
|
|||||||
@@ -18,12 +18,12 @@ use viperus::Viperus;
|
|||||||
pub fn parse_args(viperus: &mut Viperus) -> Result<(), Box<dyn std::error::Error>> {
|
pub fn parse_args(viperus: &mut Viperus) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
if cfg!(feature = "global") {
|
if cfg!(feature = "global") {
|
||||||
trace!(target: "Viperus", "Viperus feature 'global' enabled.");
|
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") {
|
if cfg!(feature = "fmt-clap") {
|
||||||
trace!(target: "Viperus", "Viperus feature 'fmt-clap' enabled.");
|
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)
|
// preset default key/value pairs (lowest priority)
|
||||||
@@ -144,10 +144,10 @@ SMR Unerledigt: 089 92529 60222")
|
|||||||
|
|
||||||
// respect dotenv environment (e.g for testing)
|
// respect dotenv environment (e.g for testing)
|
||||||
// -> overwrites the preset default values
|
// -> overwrites the preset default values
|
||||||
println!(
|
//println!(
|
||||||
"RUST_LOG={}",
|
// "RUST_LOG={}",
|
||||||
dotenv::var("RUST_LOG").unwrap_or_else(|_| String::from("None"))
|
// dotenv::var("RUST_LOG").unwrap_or_else(|_| String::from("None"))
|
||||||
);
|
//);
|
||||||
|
|
||||||
// enable caching and automatic update of environment values
|
// enable caching and automatic update of environment values
|
||||||
viperus.cache(true);
|
viperus.cache(true);
|
||||||
|
|||||||
@@ -89,11 +89,16 @@ pub fn import(p: &mut String, data_list: &mut PolicyDataList,
|
|||||||
for p in &my_policy_numbers {
|
for p in &my_policy_numbers {
|
||||||
match policy_numbers.get(&p) {
|
match policy_numbers.get(&p) {
|
||||||
Some(policy_code) => {
|
Some(policy_code) => {
|
||||||
println!("Test: Policy-Number {:?} => Policy-Type {:?}, as expected!",
|
//println!("Test: Policy-Number {:?} => Policy-Type {:?}, as expected!",
|
||||||
p, policy_code);
|
// 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trace!(target: "advotrackerd", process = "import", state = "finished", date_stop = ?dt_end.to_string());
|
trace!(target: "advotrackerd", process = "import", state = "finished", date_stop = ?dt_end.to_string());
|
||||||
|
|||||||
@@ -249,7 +249,6 @@ impl Template for PolicyCheckView {
|
|||||||
.text("")
|
.text("")
|
||||||
.on_activate(move |ctx, entity| {
|
.on_activate(move |ctx, entity| {
|
||||||
// Entity is entered/activated via Mouse/Keyboard
|
// Entity is entered/activated via Mouse/Keyboard
|
||||||
println!("activation finished!");
|
|
||||||
ctx.get_mut::<PolicyCheckState>(id)
|
ctx.get_mut::<PolicyCheckState>(id)
|
||||||
.action(Action::ParseEntry(entity));
|
.action(Action::ParseEntry(entity));
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user