Skip to content

Commit

Permalink
Use consistent timestamps in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dlon committed Sep 23, 2024
1 parent e4765ca commit 0ae8391
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions test/test-manager/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct LoggerInner {

struct StoredRecord {
level: log::Level,
time: chrono::DateTime<chrono::Local>,
time: chrono::DateTime<chrono::Utc>,
mod_path: String,
text: String,
}
Expand Down Expand Up @@ -70,7 +70,12 @@ impl Logger {
for stored_record in std::mem::take(&mut inner.stored_records) {
println!(
"[{} {} {}] {}",
stored_record.time, stored_record.level, stored_record.mod_path, stored_record.text
stored_record
.time
.to_rfc3339_opts(chrono::SecondsFormat::Secs, true),
stored_record.level,
stored_record.mod_path,
stored_record.text
);
}
}
Expand Down Expand Up @@ -99,7 +104,7 @@ impl log::Log for Logger {
let mod_path = record.module_path().unwrap_or("");
inner.stored_records.push(StoredRecord {
level: record.level(),
time: chrono::Local::now(),
time: chrono::Utc::now(),
mod_path: mod_path.to_owned(),
text: record.args().to_string(),
});
Expand Down Expand Up @@ -193,7 +198,11 @@ impl TestResult {

macro_rules! println_with_time {
($fmt:tt$(, $($args:tt)*)?) => {
println!(concat!("[{}] ", $fmt), chrono::Local::now(), $($($args)*)?)
println!(
concat!("[{}] ", $fmt),
chrono::Utc::now().to_rfc3339_opts(chrono::SecondsFormat::Secs, true),
$($($args)*)?
)
};
}

Expand Down

0 comments on commit 0ae8391

Please sign in to comment.