Skip to content

Commit 0373926

Browse files
committed
print time in status logs
1 parent f23e6fc commit 0373926

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

progress_bar.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#include <cmath>
55
#include <cassert>
66
#include <cstdio>
7+
#include <chrono>
8+
#include <ctime>
9+
#include <sstream>
710

811
#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
912
#include <unistd.h>
@@ -131,9 +134,17 @@ void ProgressBar::ShowProgress() const {
131134
assert(progress_ratio <= 1.0);
132135

133136
if (logging_mode_) {
134-
*out << get_progress_summary(progress_ratio)
135-
+ ", " + std::to_string(progress_) + "/" + std::to_string(total_) + '\n';
136-
out->flush();
137+
// get current time
138+
auto now = std::chrono::system_clock::now();
139+
std::time_t time = std::chrono::system_clock::to_time_t(now);
140+
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(
141+
now.time_since_epoch()) % 1000;
142+
std::stringstream os;
143+
os << std::put_time(std::localtime(&time), "[%F %T.")
144+
<< std::setfill('0') << std::setw(3) << ms.count() << "]\t"
145+
<< get_progress_summary(progress_ratio)
146+
<< ", " + std::to_string(progress_) + "/" + std::to_string(total_) + '\n';
147+
*out << os.str() << std::flush;
137148
return;
138149
}
139150

0 commit comments

Comments
 (0)