Skip to content

Commit 6246636

Browse files
committed
Add timestamp to test outcome logs
1 parent 1d09332 commit 6246636

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

test/test-manager/src/logging.rs

+24-14
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,21 @@ impl TestResult {
191191
}
192192
}
193193

194+
macro_rules! println_with_time {
195+
($($arg:tt)*) => {
196+
println!("[{}] {}", chrono::Local::now(), format!($($arg)*))
197+
};
198+
}
199+
194200
impl TestOutput {
195201
pub fn print(&self) {
196202
match &self.result {
197203
TestResult::Pass => {
198-
println!("{}", format!("TEST {} SUCCEEDED!", self.test_name).green());
204+
println_with_time!("{}", format!("TEST {} SUCCEEDED!", self.test_name).green());
199205
return;
200206
}
201207
TestResult::Fail(e) => {
202-
println!(
208+
println_with_time!(
203209
"{}",
204210
format!(
205211
"TEST {} RETURNED ERROR: {}",
@@ -210,7 +216,7 @@ impl TestOutput {
210216
);
211217
}
212218
TestResult::Panic(panic_msg) => {
213-
println!(
219+
println_with_time!(
214220
"{}",
215221
format!(
216222
"TEST {} PANICKED WITH MESSAGE: {}",
@@ -222,43 +228,47 @@ impl TestOutput {
222228
}
223229
}
224230

225-
println!("{}", format!("TEST {} HAD LOGS:", self.test_name).red());
231+
println_with_time!("{}", format!("TEST {} HAD LOGS:", self.test_name).red());
226232
match &self.log_output {
227233
Some(log) => {
228234
match &log.settings_json {
229-
Ok(settings) => println!("settings.json: {}", settings),
230-
Err(e) => println!("Could not get settings.json: {}", e),
235+
Ok(settings) => println_with_time!("settings.json: {}", settings),
236+
Err(e) => println_with_time!("Could not get settings.json: {}", e),
231237
}
232238

233239
match &log.log_files {
234240
Ok(log_files) => {
235241
for log in log_files {
236242
match log {
237243
Ok(log) => {
238-
println!("Log {}:\n{}", log.name.to_str().unwrap(), log.content)
244+
println_with_time!(
245+
"Log {}:\n{}",
246+
log.name.to_str().unwrap(),
247+
log.content
248+
)
239249
}
240-
Err(e) => println!("Could not get log: {}", e),
250+
Err(e) => println_with_time!("Could not get log: {}", e),
241251
}
242252
}
243253
}
244-
Err(e) => println!("Could not get logs: {}", e),
254+
Err(e) => println_with_time!("Could not get logs: {}", e),
245255
}
246256
}
247-
None => println!("Missing logs for {}", self.test_name),
257+
None => println_with_time!("Missing logs for {}", self.test_name),
248258
}
249259

250-
println!(
260+
println_with_time!(
251261
"{}",
252262
format!("TEST RUNNER {} HAD RUNTIME OUTPUT:", self.test_name).red()
253263
);
254264
if self.error_messages.is_empty() {
255-
println!("<no output>");
265+
println_with_time!("<no output>");
256266
} else {
257267
for msg in &self.error_messages {
258-
println!("{}", msg);
268+
println_with_time!("{}", msg);
259269
}
260270
}
261271

262-
println!("{}", format!("TEST {} END OF OUTPUT", self.test_name).red());
272+
println_with_time!("{}", format!("TEST {} END OF OUTPUT", self.test_name).red());
263273
}
264274
}

0 commit comments

Comments
 (0)