Skip to content

Commit 1df6987

Browse files
authored
Fix incorrect microsecond extraction in logging timestamps (#844)
This PR fixes an issue in the logging module where the microsecond part of the timestamp was calculated incorrectly. Previously, the code used: auto its_ms = (when_.time_since_epoch().count() / 100) % 1000000; However, this approach incorrectly scaled the raw duration count. The correct division factor should have been 1000 (not100), or better yet, the calculation can be performed in a type-safe manner using std::chrono::duration_cast. The updated code now correctly extracts the microsecond portion by converting the duration to microseconds.
1 parent e043515 commit 1df6987

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/build*/*
33
/examples/hello_world/build
44
/.idea/
5+
/.vs/
56
/.vscode/
67
/.settings
78
/.project

implementation/logger/src/message.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ message::~message() try {
119119
#else
120120
localtime_r(&its_time_t, &its_time);
121121
#endif
122-
auto its_ms = (when_.time_since_epoch().count() / 100) % 1000000;
122+
auto its_ms = std::chrono::duration_cast<std::chrono::microseconds>(when_.time_since_epoch()).count() % 1000000;
123123

124124
if (its_logger->has_console_log()) {
125125
#ifndef ANDROID

0 commit comments

Comments
 (0)