summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/common/Logging.cpp36
-rw-r--r--lib/common/Logging.h2
2 files changed, 27 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
diff --git a/lib/common/Logging.h b/lib/common/Logging.h
index 9753fc88..78db2bea 100644
--- a/lib/common/Logging.h
+++ b/lib/common/Logging.h
@@ -118,6 +118,7 @@ class Console : public Logger
{
private:
static bool sShowTime;
+ static bool sShowTimeMicros;
static bool sShowTag;
static std::string sTag;
@@ -129,6 +130,7 @@ class Console : public Logger
static void SetTag(const std::string& rTag);
static void SetShowTime(bool enabled);
+ static void SetShowTimeMicros(bool enabled);
};
// --------------------------------------------------------------------------