Skip to content

Commit 6e42854

Browse files
fix 4 year old Junior code
1 parent 64107fe commit 6e42854

1 file changed

Lines changed: 4 additions & 9 deletions

File tree

include/nbl/system/ILogger.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,15 @@ class ILogger : public core::IReferenceCounted
6161
using namespace std::chrono;
6262
auto currentTime = std::chrono::system_clock::now();
6363
const std::time_t t = std::chrono::system_clock::to_time_t(currentTime);
64-
65-
// Since there is no real way in c++ to get current time with microseconds, this is my weird approach
66-
auto time_since_epoch = duration_cast<microseconds>(system_clock::now().time_since_epoch());
67-
auto time_since_epoch_s = duration_cast<seconds>(system_clock::now().time_since_epoch());
68-
time_since_epoch -= duration_cast<microseconds>(time_since_epoch_s);
69-
70-
// This while is for the microseconds which are less that 6 digits long to be aligned with the others
71-
while (time_since_epoch.count() / 100000 == 0) time_since_epoch *= 10;
7264

7365
auto time = std::localtime(&t);
7466

67+
// since there's no microseconds in `time`
68+
const auto us_fraction = duration_cast<microseconds>(currentTime.time_since_epoch()) - duration_cast<microseconds>(duration_cast<seconds>(currentTime.time_since_epoch()));
69+
7570
constexpr size_t DATE_STR_LENGTH = 28;
7671
std::string timeStr(DATE_STR_LENGTH, '\0');
77-
sprintf(timeStr.data(), "[%02d.%02d.%d %02d:%02d:%02d:%d]", time->tm_mday, time->tm_mon + 1, 1900 + time->tm_year, time->tm_hour, time->tm_min, time->tm_sec, (int)time_since_epoch.count());
72+
sprintf(timeStr.data(), "[%02d.%02d.%d %02d:%02d:%02d:%06d]", time->tm_mday, time->tm_mon + 1, 1900 + time->tm_year, time->tm_hour, time->tm_min, time->tm_sec, (int)us_fraction.count());
7873

7974
std::string messageTypeStr;
8075
switch (logLevel)

0 commit comments

Comments
 (0)