From 60fc3adfa71957c2700de2c691e9dd84813de708 Mon Sep 17 00:00:00 2001 From: Stefan Heule Date: Mon, 2 Sep 2024 12:37:56 -0700 Subject: [PATCH] Improve logging --- src/lib.rs | 36 ++++++++++++++++++++++++--------- src/models/piranha_arguments.rs | 4 ++-- src/models/source_code_unit.rs | 2 +- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0a65229e2..aa184db0f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,8 +60,6 @@ fn polyglot_piranha(_py: Python<'_>, m: &PyModule) -> PyResult<()> { /// For each file, it reports its content after the rewrite, the list of matches and the list of rewrites. #[pyfunction] pub fn execute_piranha(piranha_arguments: &PiranhaArguments) -> Vec { - info!("Executing Polyglot Piranha !!!"); - let mut piranha = Piranha::new(piranha_arguments); piranha.perform_cleanup(); @@ -80,15 +78,35 @@ fn log_piranha_output_summaries(summaries: &Vec) { for summary in summaries { let number_of_rewrites = &summary.rewrites().len(); let number_of_matches = &summary.matches().len(); - info!("File : {:?}", &summary.path()); - info!(" # Rewrites : {}", number_of_rewrites); - info!(" # Matches : {}", number_of_matches); + info!( + "File: {:?} with {} matches and {} rewrites", + &summary.path(), + number_of_matches, + number_of_rewrites + ); + if *number_of_rewrites > 0 { + let used_rules: Vec<&String> = summary + .rewrites() + .iter() + .map(|r| r.matched_rule()) + .collect(); + let deduplicated_rules: Vec<&String> = used_rules.into_iter().unique().collect(); + info!( + "Rewrites used the following rules: {}", + deduplicated_rules.into_iter().join(", ") + ); + } total_number_of_rewrites += number_of_rewrites; total_number_of_matches += number_of_matches; } - info!("Total files affected/matched {}", &summaries.len()); - info!("Total number of matches {}", total_number_of_matches); - info!("Total number of rewrites {}", total_number_of_rewrites); + if summaries.len() > 1 { + info!( + "Total files: {} (with {} matches and {} rewrites)", + &summaries.len(), + total_number_of_matches, + total_number_of_rewrites + ); + } } // Maintains the state of Piranha and the updated content of files in the source code. @@ -197,7 +215,7 @@ impl Piranha { /// Write the input code snippet into a temp directory. /// Returns: A temporary directory containing the created input code snippet as a file - /// This function panics if it finds that neither `code_snippet` nor `path_to_configuration` are provided + /// This function panics if it finds that neither `code_snippet` nor `path_to_configuration` are provided fn write_code_snippet_to_temp(&self) -> TempDir { let temp_dir = TempDir::new_in(".", "tmp").unwrap(); let temp_dir_path = temp_dir.path(); diff --git a/src/models/piranha_arguments.rs b/src/models/piranha_arguments.rs index aaf429160..50370f39b 100644 --- a/src/models/piranha_arguments.rs +++ b/src/models/piranha_arguments.rs @@ -32,7 +32,7 @@ use derive_builder::Builder; use getset::{CopyGetters, Getters}; use glob::Pattern; use itertools::Itertools; -use log::{info, warn}; +use log::{debug, warn}; use pyo3::{ prelude::{pyclass, pymethods}, types::PyDict, @@ -317,7 +317,7 @@ impl PiranhaArgumentsBuilder { let rule_graph = get_rule_graph(&_arg); _arg = PiranhaArguments { rule_graph, .._arg }; #[rustfmt::skip] - info!( "Number of rules and edges loaded : {:?}", _arg.rule_graph().get_number_of_rules_and_edges()); + debug!( "Number of rules and edges loaded : {:?}", _arg.rule_graph().get_number_of_rules_and_edges()); _arg } } diff --git a/src/models/source_code_unit.rs b/src/models/source_code_unit.rs index c9fcc9162..65487fcc9 100644 --- a/src/models/source_code_unit.rs +++ b/src/models/source_code_unit.rs @@ -220,7 +220,7 @@ impl SourceCodeUnit { .iter() .map(|(k, v)| { let rules = v.iter().map(|f| f.name()).join(", "); - format!("Next Rules:\nScope {k} \nRules {rules}").blue() + format!("Next Rules:\n- Scope {k} \n- Rules {rules}").blue() }) .join("\n") );