Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve logging problem #231

Merged
merged 2 commits into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions polyglot/piranha/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ impl FlagCleaner {
.iter()
.any(|x| x.holes().is_empty());
let pattern = self.get_grep_heuristics();
info!("{}", format!("Searching pattern {}", pattern).green());
let files: HashMap<PathBuf, String> = WalkDir::new(&self.path_to_codebase)
// Walk over the entire code base
.into_iter()
Expand All @@ -410,7 +409,7 @@ impl FlagCleaner {
.filter(|x| no_global_rules_with_holes || pattern.is_match(x.1.as_str()))
.collect();
#[rustfmt::skip]
println!("{}", format!("Will parse and analyze {} files.", files.len()).green());
info!("{}", format!("Will parse and analyze {} files.", files.len()).green());
files
}

Expand Down
4 changes: 2 additions & 2 deletions polyglot/piranha/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ use std::{fs, time::Instant};
use log::info;
use polyglot_piranha::{
execute_piranha, models::piranha_arguments::PiranhaArguments,
models::piranha_output::PiranhaOutputSummary, utilities::initialize_logger,
models::piranha_output::PiranhaOutputSummary,
};

fn main() {
let now = Instant::now();
initialize_logger(false);
env_logger::init();

let args = PiranhaArguments::from_command_line();

Expand Down
2 changes: 1 addition & 1 deletion polyglot/piranha/src/models/piranha_arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl PiranhaArguments {
let input_substitutions = piranha_args_from_config.substitutions();

#[rustfmt::skip]
info!("{}", format!("Piranha arguments are :\n {:?}", input_substitutions).purple());
info!("{}", format!("Piranha arguments are :\n {:?}", input_substitutions).purple());

let mut args_builder = PiranhaArgumentsBuilder::default();

Expand Down
2 changes: 1 addition & 1 deletion polyglot/piranha/src/models/rule_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Copyright (c) 2022 Uber Technologies, Inc.
use std::collections::HashMap;

use colored::Colorize;
use log::info;
use log::{info};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed? I think log::info is the right syntax if we are just importing that, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YEs. Addressed by cargo format.

I think I ll add a new Github action that runs cargo format on each PR, as a commit. Idk

use tree_sitter::{Language, Query};

use crate::{
Expand Down
1 change: 0 additions & 1 deletion polyglot/piranha/src/models/source_code_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ impl SourceCodeUnit {
} else {
None
};
println!("Replacing file contents");
// Create a new updated tree from the previous tree
let new_tree = parser
.parse(&replacement_content, prev_tree)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ fn test_apply_edit_comma_handling_via_grammar() {
&Edit::dummy_edit(range(37, 47, 2, 26, 2, 36), String::new()),
&mut parser,
);
println!("{}", &source_code_unit.code());
assert!(eq_without_whitespace(
&source_code.replace("\"NullAway\",", ""),
&source_code_unit.code()
Expand All @@ -144,7 +143,6 @@ fn test_apply_edit_comma_handling_via_regex() {
&Edit::dummy_edit(range(59, 75, 3, 23, 3, 41), String::new()),
&mut parser,
);
println!("{}", &source_code_unit.code());
assert!(eq_without_whitespace(
&source_code.replace("name: \"BMX Bike\",", ""),
&source_code_unit.code()
Expand Down
8 changes: 5 additions & 3 deletions polyglot/piranha/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ Copyright (c) 2022 Uber Technologies, Inc.

use std::path::{Path, PathBuf};

use log::{error};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use log::error


use crate::config::CommandLineArguments;
use crate::execute_piranha;
use crate::models::piranha_arguments::PiranhaArguments;
use crate::models::piranha_output::PiranhaOutputSummary;
use crate::utilities::{eq_without_whitespace, find_file, initialize_logger, read_file};
use crate::utilities::{eq_without_whitespace, find_file, read_file};

mod test_piranha_java;
mod test_piranha_kt;
Expand All @@ -32,7 +34,7 @@ static INIT: Once = Once::new();

fn initialize() {
INIT.call_once(|| {
initialize_logger(true);
env_logger::init();
});
}

Expand Down Expand Up @@ -99,7 +101,7 @@ fn check_result(updated_files: Vec<PiranhaOutputSummary>, path_to_expected: Path

if !eq_without_whitespace(source_code_unit.content(), &expected_content) {
all_files_match = false;
println!("{}", &source_code_unit.content());
error!("{}", &source_code_unit.content());
}
}
assert!(all_files_match);
Expand Down
18 changes: 1 addition & 17 deletions polyglot/piranha/src/utilities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ Copyright (c) 2022 Uber Technologies, Inc.
*/

pub(crate) mod tree_sitter_utilities;

use std::collections::HashMap;
#[cfg(test)]
use std::fs::{self, DirEntry};
use std::fs::{File, OpenOptions};
use std::fs::File;
use std::hash::Hash;
use std::io::{BufReader, Read};
use std::path::PathBuf;
Expand Down Expand Up @@ -65,21 +64,6 @@ impl<T: Hash + Eq, U> MapOfVec<T, U> for HashMap<T, Vec<U>> {
}
}

/// Initialize logger.
pub fn initialize_logger(is_test: bool) {
let log_file = OpenOptions::new()
.write(true)
.create(true) // Create a log file if it doesn't exists
.append(true) // Append to the log file if it exists
.open("piranha.log")
.unwrap();
let _ = env_logger::builder()
.format_timestamp(None)
.target(env_logger::Target::Pipe(Box::new(log_file)))
.is_test(is_test)
.try_init();
}

/// Compares two strings, ignoring whitespace
pub(crate) fn eq_without_whitespace(s1: &str, s2: &str) -> bool {
s1.split_whitespace()
Expand Down
2 changes: 1 addition & 1 deletion polyglot/piranha/src/utilities/tree_sitter_utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
};
use colored::Colorize;
use itertools::Itertools;
use log::info;
use log::{info};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I missing something about log::{info} vs log::info

Copy link
Contributor Author

@ketkarameya ketkarameya Sep 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No its equivalent.
I think during my changes I had added a warn macro in this file and made this import ->
log::info -> log::{info, warn}. But then I removed warn, and {} remained. I will clean i up.

use std::collections::HashMap;
#[cfg(test)]
use tree_sitter::Parser;
Expand Down