Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3007)

Unified Diff: base/logging.cc

Issue 2536203005: base: Print sub-second resolution timestamps (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/logging.cc
diff --git a/base/logging.cc b/base/logging.cc
index 0771b47c182e5c18c868f1124a0784bf411d74a9..e0ca19933e75d546cb18c755c0f8024b23de776d 100644
--- a/base/logging.cc
+++ b/base/logging.cc
@@ -765,13 +765,12 @@ void LogMessage::Init(const char* file, int line) {
if (g_log_thread_id)
stream_ << base::PlatformThread::CurrentId() << ':';
if (g_log_timestamp) {
- time_t t = time(nullptr);
- struct tm local_time = {0};
-#ifdef _MSC_VER
- localtime_s(&local_time, &t);
-#else
+#if defined(OS_POSIX)
+ timeval tv;
+ gettimeofday(&tv, nullptr);
+ time_t t = tv.tv_sec;
+ struct tm local_time;
localtime_r(&t, &local_time);
-#endif
struct tm* tm_time = &local_time;
stream_ << std::setfill('0')
<< std::setw(2) << 1 + tm_time->tm_mon
@@ -780,7 +779,23 @@ void LogMessage::Init(const char* file, int line) {
<< std::setw(2) << tm_time->tm_hour
<< std::setw(2) << tm_time->tm_min
<< std::setw(2) << tm_time->tm_sec
+ << '.'
+ << std::setw(6) << tv.tv_usec
<< ':';
+#elif defined(OS_WIN)
+ SYSTEMTIME local_time;
+ GetLocalTime(&local_time);
+ stream_ << std::setfill('0')
+ << std::setw(2) << local_time.wMonth
+ << std::setw(2) << local_time.wDay
+ << '/'
+ << std::setw(2) << local_time.wHour
+ << std::setw(2) << local_time.wMinute
+ << std::setw(2) << local_time.wSecond
+ << '.'
+ << std::setw(3) << local_time.wMilliseconds
+ << ':';
+#endif
}
if (g_log_tickcount)
stream_ << TickCount() << ':';
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698