Skip to content

Commit 350dd23

Browse files
committed
feat: improve log messages verbosity and style
1 parent a711e65 commit 350dd23

6 files changed

Lines changed: 44 additions & 24 deletions

File tree

src/app.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use crate::{
2-
api_client::CodSpeedAPIClient, auth, local_logger::CODSPEED_U8_COLOR_CODE, prelude::*, run,
3-
setup,
2+
api_client::CodSpeedAPIClient,
3+
auth,
4+
local_logger::{init_local_logger, CODSPEED_U8_COLOR_CODE},
5+
prelude::*,
6+
run, setup,
47
};
58
use clap::{
69
builder::{styling, Styles},
@@ -48,6 +51,13 @@ pub async fn run() -> Result<()> {
4851
let cli = Cli::parse();
4952
let api_client = CodSpeedAPIClient::try_from(&cli)?;
5053

54+
match cli.command {
55+
Commands::Run(_) => {} // Run is responsible for its own logger initialization
56+
_ => {
57+
init_local_logger()?;
58+
}
59+
}
60+
5161
match cli.command {
5262
Commands::Run(args) => run::run(args, &api_client).await?,
5363
Commands::Auth(args) => auth::run(args, &api_client).await?,

src/auth.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use std::time::Duration;
22

3-
use crate::local_logger::get_local_logger;
43
use crate::{api_client::CodSpeedAPIClient, config::CodSpeedConfig, prelude::*};
54
use clap::{Args, Subcommand};
65
use console::style;
7-
use simplelog::CombinedLogger;
86
use tokio::time::{sleep, Instant};
97

108
#[derive(Debug, Args)]
@@ -19,15 +17,7 @@ enum AuthCommands {
1917
Login,
2018
}
2119

22-
fn init_logger() -> Result<()> {
23-
let logger = get_local_logger();
24-
CombinedLogger::init(vec![logger])?;
25-
Ok(())
26-
}
27-
2820
pub async fn run(args: AuthArgs, api_client: &CodSpeedAPIClient) -> Result<()> {
29-
init_logger()?;
30-
3121
match args.command {
3222
AuthCommands::Login => login(api_client).await?,
3323
}

src/local_logger.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ use std::{
44
time::Duration,
55
};
66

7+
use crate::prelude::*;
78
use console::{style, Style};
89
use indicatif::{ProgressBar, ProgressStyle};
910
use lazy_static::lazy_static;
1011
use log::Log;
11-
use simplelog::SharedLogger;
12+
use simplelog::{CombinedLogger, SharedLogger};
1213
use std::io::Write;
1314

1415
use crate::logger::{get_group_event, GroupEvent};
1516

1617
pub const CODSPEED_U8_COLOR_CODE: u8 = 208; // #FF8700
17-
const BLACK_U8_COLOR_CODE: u8 = 16; // #000
1818

1919
lazy_static! {
2020
pub static ref SPINNER: Arc<Mutex<Option<ProgressBar>>> = Arc::new(Mutex::new(None));
@@ -67,13 +67,11 @@ impl Log for LocalLogger {
6767
match group_event {
6868
GroupEvent::Start(name) | GroupEvent::StartOpened(name) => {
6969
println!(
70-
" {}",
71-
style(format!(" {} ", name.to_uppercase()))
70+
"\n{}",
71+
style(format!("►►► {} ", name))
7272
.bold()
73-
.color256(BLACK_U8_COLOR_CODE)
74-
.on_color256(CODSPEED_U8_COLOR_CODE)
73+
.color256(CODSPEED_U8_COLOR_CODE)
7574
);
76-
println!();
7775

7876
if *IS_TTY {
7977
let spinner = ProgressBar::new_spinner();
@@ -158,6 +156,12 @@ pub fn get_local_logger() -> Box<dyn SharedLogger> {
158156
Box::new(LocalLogger::new())
159157
}
160158

159+
pub fn init_local_logger() -> Result<()> {
160+
let logger = get_local_logger();
161+
CombinedLogger::init(vec![logger])?;
162+
Ok(())
163+
}
164+
161165
pub fn clean_logger() {
162166
let mut spinner = SPINNER.lock().unwrap();
163167
if let Some(spinner) = spinner.as_mut() {

src/run/check_system.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,18 @@ pub fn check_system(system_info: &SystemInfo) -> Result<()> {
130130

131131
match system_info.arch.as_str() {
132132
"x86_64" | "aarch64" => {
133-
warn!("Unsupported system: {:?}", system_info);
134-
warn!("Continuing with best effort support");
133+
warn!(
134+
"Unofficially supported system: {} {}. Continuing with best effort support.",
135+
system_info.os, system_info.os_version
136+
);
135137
return Ok(());
136138
}
137139
_ => {}
138140
}
139141

140-
bail!("Unsupported system: {:?}", system_info);
142+
bail!(
143+
"Unsupported system: {} {}",
144+
system_info.os,
145+
system_info.os_version
146+
);
141147
}

src/run/runner/valgrind/setup.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,15 @@ fn is_valgrind_installed() -> bool {
7373
}
7474

7575
let version = String::from_utf8_lossy(&version_output.stdout);
76-
version.contains(VALGRIND_CODSPEED_VERSION.as_str())
76+
let result = version.contains(VALGRIND_CODSPEED_VERSION.as_str());
77+
if !result {
78+
warn!(
79+
"Valgrind is installed but the version is not the expected one. expecting {} but found installed: {}",
80+
VALGRIND_CODSPEED_VERSION.as_str(),
81+
version
82+
);
83+
}
84+
result
7785
} else {
7886
false
7987
}

src/setup.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ use crate::run::runner::get_all_executors;
55
pub async fn setup() -> Result<()> {
66
let system_info = SystemInfo::new()?;
77
let executors = get_all_executors();
8-
info!("Setting up the environment for all executors");
8+
start_group!("Setting up the environment for all executors");
99
for executor in executors {
1010
info!(
1111
"Setting up the environment for the executor: {}",
1212
executor.name().to_string()
1313
);
1414
executor.setup(&system_info).await?;
1515
}
16+
info!("Environment setup completed");
17+
end_group!();
1618
Ok(())
1719
}

0 commit comments

Comments
 (0)