Skip to content

Commit

Permalink
WIP switch to simplelog
Browse files Browse the repository at this point in the history
`env_logger` does not handle writing to file for the moment, see rust-cli/env_logger#208
  • Loading branch information
kraktus committed Oct 26, 2022
1 parent 1720b5b commit 7325e03
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lintcheck/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ publish = false
cargo_metadata = "0.14"
clap = "3.2"
crossbeam-channel = "0.5.6"
env_logger = "0.9"
simplelog = "0.12.0"
flate2 = "1.0"
log = "0.4"
rayon = "1.5.1"
Expand Down
37 changes: 21 additions & 16 deletions lintcheck/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use clap::{Arg, ArgAction, ArgMatches, Command};
use env_logger::Builder;
use log::LevelFilter;
use simplelog::{ColorChoice, CombinedLogger, Config, TermLogger, TerminalMode, WriteLogger};
use std::env;
use std::fs::{self, File};
use std::path::PathBuf;

fn get_clap_config() -> ArgMatches {
Expand Down Expand Up @@ -58,6 +59,8 @@ pub(crate) struct LintcheckConfig {
pub sources_toml_path: PathBuf,
/// we save the clippy lint results here
pub lintcheck_results_path: PathBuf,
// /// we save the clippy logs here
// pub lintcheck_log_path: PathBuf,
/// Check only a specified package
pub only: Option<String>,
/// whether to just run --fix and not collect all the warnings
Expand All @@ -73,22 +76,24 @@ pub(crate) struct LintcheckConfig {
impl LintcheckConfig {
pub fn new() -> Self {
let clap_config = get_clap_config();
let mut builder = Builder::new();
builder
.filter(
None,
match clap_config.get_count("verbose") {
0 => LevelFilter::Warn,
1 => LevelFilter::Info,
2 => dbg!(LevelFilter::Debug),
_ => LevelFilter::Trace,
},
)
.default_format()
.init();
assert_eq!(clap_config.get_count("verbose"), 2);
let level_filter = match clap_config.get_count("verbose") {
0 => LevelFilter::Warn,
1 => LevelFilter::Info,
2 => dbg!(LevelFilter::Debug),
_ => LevelFilter::Trace,
};
// creating the dir that will contain the log and results
fs::create_dir("lintcheck-logs").expect("Creating the log dir failed");
let _ = CombinedLogger::init(vec![
TermLogger::new(level_filter, Config::default(), TerminalMode::Mixed, ColorChoice::Auto),
WriteLogger::new(
level_filter,
Config::default(),
File::create("lintcheck-logs/lintcheck.log").unwrap(),
),
]);
// assert_eq!(clap_config.get_count("verbose"), 2);
log::debug!("Test");
println!("{:?}", builder);

// first, check if we got anything passed via the LINTCHECK_TOML env var,
// if not, ask clap if we got any value for --crates-toml <foo>
Expand Down
1 change: 0 additions & 1 deletion lintcheck/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,6 @@ fn main() {
}

println!("Writing logs to {}", config.lintcheck_results_path.display());
fs::create_dir_all(config.lintcheck_results_path.parent().unwrap()).unwrap();
fs::write(&config.lintcheck_results_path, text).unwrap();

print_stats(old_stats, new_stats, &config.lint_filter);
Expand Down

0 comments on commit 7325e03

Please sign in to comment.