Skip to content

Commit

Permalink
feat: Tweak logging and add cli option to customize log level
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedroh committed May 25, 2024
1 parent 83a66ab commit c7b77e4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions bin/src/cli_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ pub struct CliArgs {
/// If not provided the language will try to be inferred by the extension of the base file.
#[arg(long)]
pub(crate) language: Option<String>,

/// The log level provided for the execution.
/// If not provided defaults to INFO.
#[arg(long)]
pub(crate) log_level: Option<log::LevelFilter>,
}
14 changes: 14 additions & 0 deletions bin/src/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,34 @@ pub fn run_tool_on_merge_scenario(

let parser_configuration = ParserConfiguration::from(language);

log::info!("Started parsing base file");
let base_tree =
parsing::parse_string(base, &parser_configuration).map_err(ExecutionError::ParsingError)?;
log::info!("Finished parsing base file");
log::info!("Started parsing left file");
let left_tree =
parsing::parse_string(left, &parser_configuration).map_err(ExecutionError::ParsingError)?;
log::info!("Finished parsing left file");
log::info!("Started parsing right file");
let right_tree = parsing::parse_string(right, &parser_configuration)
.map_err(ExecutionError::ParsingError)?;
log::info!("Finished parsing right file");

let matching_configuration = matching_configuration::MatchingConfiguration::from(language);
log::info!("Started calculation of matchings between left and base");
let matchings_left_base =
matching::calculate_matchings(&left_tree, &base_tree, &matching_configuration);
log::info!("Finished calculation of matchings between left and base");
log::info!("Started calculation of matchings between right and base");
let matchings_right_base =
matching::calculate_matchings(&right_tree, &base_tree, &matching_configuration);
log::info!("Finished calculation of matchings between right and base");
log::info!("Started calculation of matchings between left and right");
let matchings_left_right =
matching::calculate_matchings(&left_tree, &right_tree, &matching_configuration);
log::info!("Finished calculation of matchings between left and right");

log::info!("Starting merge of the trees");
let result = merge::merge(
&base_tree,
&left_tree,
Expand All @@ -82,6 +95,7 @@ pub fn run_tool_on_merge_scenario(
&matchings_left_right,
)
.map_err(ExecutionError::MergeError)?;
log::info!("Finished merge of the trees");

match result.has_conflict() {
true => Ok(ExecutionResult::WithConflicts(result.to_string())),
Expand Down
6 changes: 4 additions & 2 deletions bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ mod language;
use clap::Parser;

fn main() {
env_logger::init();

let args = cli_args::CliArgs::parse();
env_logger::builder().filter_level(args.log_level.unwrap_or(log::LevelFilter::Info)).init();

log::info!("Starting Generic Merge tool execution");
log::debug!("Parsed arguments: {:?}", args);

let base = std::fs::read_to_string(&args.base_path).unwrap_or_else(|error| {
log::error!("Error while reading base file: {}", error);
Expand Down

0 comments on commit c7b77e4

Please sign in to comment.