summaryrefslogtreecommitdiff
path: root/src/SimpleLogger.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-09-23 10:44:43 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-09-23 10:44:43 +0000
commit2522175ff153c4f52bc4b40c062c98fcc376c49e (patch)
treea33c709acdf1c8c5a3b6c6992f0254220596a61d /src/SimpleLogger.cc
parent2c6d2cd5623cd9bbacb500f7bf3e48c1d19faeb6 (diff)
2008-09-23 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Log microseconds. * src/SimpleLogger.cc (SimpleLogger::writeLog)
Diffstat (limited to 'src/SimpleLogger.cc')
-rw-r--r--src/SimpleLogger.cc14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/SimpleLogger.cc b/src/SimpleLogger.cc
index d4d8f9e0..b44b3da8 100644
--- a/src/SimpleLogger.cc
+++ b/src/SimpleLogger.cc
@@ -44,6 +44,7 @@
#include <cstring>
#include <iostream>
#include <cstdlib>
+#include <cassert>
namespace aria2 {
@@ -142,11 +143,16 @@ void SimpleLogger::writeLog(std::ostream& o, Logger::LEVEL level,
default:
levelStr = INFO;
}
- time_t now = time(NULL);
- char datestr[20];
+ struct timeval tv;
+ gettimeofday(&tv, 0);
+ char datestr[27]; // 'YYYY-MM-DD hh:mm:ss.uuuuuu'+'\0' = 27 bytes
struct tm tm;
- localtime_r(&now, &tm);
- strftime(datestr, sizeof(datestr), "%Y-%m-%d %H:%M:%S", &tm);
+ localtime_r(&tv.tv_sec, &tm);
+ size_t dateLength =
+ strftime(datestr, sizeof(datestr), "%Y-%m-%d %H:%M:%S", &tm);
+ assert(dateLength <= (size_t)20);
+ snprintf(datestr+dateLength, sizeof(datestr)-dateLength,
+ ".%06ld", tv.tv_usec);
// TODO a quick hack not to print header in console
if(printHeader) {