summaryrefslogtreecommitdiff
path: root/src/log.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2006-11-26 21:51:01 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2006-11-26 21:51:01 +0000
commita8a90f2df98e13971566af63567e31da4666b1c9 (patch)
treedfabbaf186faeb262f72948aea94b1ad160420a4 /src/log.cpp
parent42f18ad42f3b908d6af849a74273a58840fa67a1 (diff)
downloadmana-a8a90f2df98e13971566af63567e31da4666b1c9.tar.gz
mana-a8a90f2df98e13971566af63567e31da4666b1c9.tar.bz2
mana-a8a90f2df98e13971566af63567e31da4666b1c9.tar.xz
mana-a8a90f2df98e13971566af63567e31da4666b1c9.zip
Higher precision log timestamps, some more logging and support for TGA images.
Diffstat (limited to 'src/log.cpp')
-rw-r--r--src/log.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/log.cpp b/src/log.cpp
index 3d101d29..347fd416 100644
--- a/src/log.cpp
+++ b/src/log.cpp
@@ -30,6 +30,7 @@
#include <cstdarg>
#include <iostream>
#include <sstream>
+#include <sys/time.h>
Logger::~Logger()
@@ -60,7 +61,6 @@ void Logger::log(const char *log_text, ...)
char* buf = new char[1024];
va_list ap;
- time_t t;
// Use a temporary buffer to fill in the variables
va_start(ap, log_text);
@@ -68,19 +68,23 @@ void Logger::log(const char *log_text, ...)
va_end(ap);
// Get the current system time
- time(&t);
+ timeval tv;
+ gettimeofday(&tv, NULL);
// Print the log entry
std::stringstream timeStr;
timeStr << "["
- << ((((t / 60) / 60) % 24 < 10) ? "0" : "")
- << (int)(((t / 60) / 60) % 24)
+ << ((((tv.tv_sec / 60) / 60) % 24 < 10) ? "0" : "")
+ << (int)(((tv.tv_sec / 60) / 60) % 24)
<< ":"
- << (((t / 60) % 60 < 10) ? "0" : "")
- << (int)((t / 60) % 60)
+ << (((tv.tv_sec / 60) % 60 < 10) ? "0" : "")
+ << (int)((tv.tv_sec / 60) % 60)
<< ":"
- << ((t % 60 < 10) ? "0" : "")
- << (int)(t % 60)
+ << ((tv.tv_sec % 60 < 10) ? "0" : "")
+ << (int)(tv.tv_sec % 60)
+ << "."
+ << (((tv.tv_usec / 10000) % 100) < 10 ? "0" : "")
+ << (int)((tv.tv_usec / 10000) % 100)
<< "] ";
mLogFile << timeStr.str() << buf << std::endl;