summaryrefslogtreecommitdiff
path: root/lib/common/Logging.cpp
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2007-12-15 20:03:50 +0000
committerChris Wilson <chris+github@qwirx.com>2007-12-15 20:03:50 +0000
commitccc0bce45b99b3fcc73b4c217ef6c2088abde4dd (patch)
tree83387af23316c76cb7f2c4b2d34c2ea3ee8b191e /lib/common/Logging.cpp
parentf5d99a3d47fd8a99ba41d909d01efdeecfddcc74 (diff)
Allow logging with microsecond timestamps.
Diffstat (limited to 'lib/common/Logging.cpp')
-rw-r--r--lib/common/Logging.cpp36
1 files changed, 25 insertions, 11 deletions
diff --git a/lib/common/Logging.cpp b/lib/common/Logging.cpp
index d22db238..2b81b52b 100644
--- a/lib/common/Logging.cpp
+++ b/lib/common/Logging.cpp
@@ -20,6 +20,8 @@
#include <iomanip>
+#include "BoxTime.h"
+
bool Logging::sLogToSyslog = false;
bool Logging::sLogToConsole = false;
bool Logging::sContextSet = false;
@@ -178,7 +180,8 @@ Logger::~Logger()
}
bool Console::sShowTime = false;
-bool Console::sShowTag = false;
+bool Console::sShowTimeMicros = false;
+bool Console::sShowTag = false;
std::string Console::sTag;
void Console::SetTag(const std::string& rTag)
@@ -192,6 +195,11 @@ void Console::SetShowTime(bool enabled)
sShowTime = enabled;
}
+void Console::SetShowTimeMicros(bool enabled)
+{
+ sShowTimeMicros = enabled;
+}
+
bool Console::Log(Log::Level level, const std::string& rFile,
int line, std::string& rMessage)
{
@@ -211,25 +219,31 @@ bool Console::Log(Log::Level level, const std::string& rFile,
if (sShowTime)
{
- struct tm time_now, *tm_ptr = &time_now;
- time_t time_t_now = time(NULL);
+ box_time_t time_now = GetCurrentBoxTime();
+ time_t seconds = BoxTimeToSeconds(time_now);
+ int micros = BoxTimeToMicroSeconds(time_now) % MICRO_SEC_IN_SEC;
+
+ struct tm tm_now, *tm_ptr = &tm_now;
- if (time_t_now == ((time_t)-1))
- {
- msg += strerror(errno);
- msg += " ";
- }
#ifdef WIN32
- else if ((tm_ptr = localtime(&time_t_now)) != NULL)
+ if ((tm_ptr = localtime(&seconds)) != NULL)
#else
- else if (localtime_r(&time_t_now, &time_now) != NULL)
+ if (localtime_r(&seconds, &tm_now) != NULL)
#endif
{
std::ostringstream buf;
+
buf << std::setfill('0') <<
std::setw(2) << tm_ptr->tm_hour << ":" <<
std::setw(2) << tm_ptr->tm_min << ":" <<
- std::setw(2) << tm_ptr->tm_sec << " ";
+ std::setw(2) << tm_ptr->tm_sec;
+
+ if (sShowTimeMicros)
+ {
+ buf << "." << std::setw(6) << micros;
+ }
+
+ buf << " ";
msg += buf.str();
}
else