2008-09-23 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Log microseconds.
	* src/SimpleLogger.cc (SimpleLogger::writeLog)
pull/1/head
Tatsuhiro Tsujikawa 2008-09-23 10:44:43 +00:00
parent 2c6d2cd562
commit 2522175ff1
2 changed files with 15 additions and 4 deletions

View File

@ -1,3 +1,8 @@
2008-09-23 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Log microseconds.
* src/SimpleLogger.cc (SimpleLogger::writeLog)
2008-09-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Replaced HelpItem.cc with OptionHandler.cc.

View File

@ -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) {