diff options
author | Randolph Tan <randolph@10gen.com> | 2012-10-31 14:56:00 -0400 |
---|---|---|
committer | Randolph Tan <randolph@10gen.com> | 2012-10-31 15:49:17 -0400 |
commit | dfbc5b910ba93f7c17463f7b7402b42c8c99321e (patch) | |
tree | ac3033362c637b0803643801c2a755118562b49f /src/mongo/util/time_support.cpp | |
parent | 44e2a3167adb48e9055639bbd9d94bd9c4d4460b (diff) | |
download | mongo-dfbc5b910ba93f7c17463f7b7402b42c8c99321e.tar.gz |
SERVER-6295 make time in log have millisecond precision
Diffstat (limited to 'src/mongo/util/time_support.cpp')
-rw-r--r-- | src/mongo/util/time_support.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/mongo/util/time_support.cpp b/src/mongo/util/time_support.cpp index 01cc9a1efcf..bad78b870fd 100644 --- a/src/mongo/util/time_support.cpp +++ b/src/mongo/util/time_support.cpp @@ -14,7 +14,7 @@ */ #include "mongo/platform/basic.h" - +#include "mongo/platform/cstdint.h" #include "mongo/util/time_support.h" #include <cstdio> @@ -49,6 +49,26 @@ namespace mongo { #endif } +#if defined(_WIN32) + void curTimeString(char* timeStr) { + boost::xtime xt; + boost::xtime_get(&xt, MONGO_BOOST_TIME_UTC); + time_t_to_String(xt.sec, timeStr); + + char* milliSecStr = timeStr + 19; + _snprintf(milliSecStr, 5, ".%03d", static_cast<int32_t>(xt.nsec / 1000000)); + } +#else + void curTimeString(char* timeStr) { + struct timeval tv; + gettimeofday(&tv, NULL); + time_t_to_String(tv.tv_sec, timeStr); + + char* milliSecStr = timeStr + 19; + snprintf(milliSecStr, 5, ".%03d", static_cast<int32_t>(tv.tv_usec / 1000)); + } +#endif + // uses ISO 8601 dates without trailing Z // colonsOk should be false when creating filenames string terseCurrentTime(bool colonsOk) { |