From 06010a46b6eeff1b16998934e38b49e1b2c8381d Mon Sep 17 00:00:00 2001 From: Andrew Scherkus Date: Tue, 6 Jul 2021 13:16:53 -0400 Subject: [PATCH] fix logging timestamps The old code was incorrectly casting a double milliseconds value to the integer seconds time_t type, which caused incorrect month/day and timestamp values in log output. Instead use absl::ToTimespec() to access the tv_sec and tv_nsec values directly. --- ortools/base/logging.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ortools/base/logging.cc b/ortools/base/logging.cc index 2adbbd3664..57865d539e 100644 --- a/ortools/base/logging.cc +++ b/ortools/base/logging.cc @@ -1140,10 +1140,10 @@ void LogMessage::Init(const char* file, int line, LogSeverity severity, data_->send_method_ = send_method; data_->sink_ = NULL; data_->outvec_ = NULL; - double now = ToUDate(absl::Now()); - data_->timestamp_ = static_cast(now); + timespec now_ts = absl::ToTimespec(absl::Now()); + data_->timestamp_ = now_ts.tv_sec; localtime_r(&data_->timestamp_, &data_->tm_time_); - int usecs = static_cast((now - data_->timestamp_) * 1000000); + int usecs = now_ts.tv_nsec / 1000; data_->num_chars_to_log_ = 0; data_->num_chars_to_syslog_ = 0;