Skip to content

Commit

Permalink
logging: Add microsecond timer to log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
popcornmix committed Jan 28, 2016
1 parent 025f98e commit 441217d
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions xbmc/utils/log.cpp
Expand Up @@ -24,6 +24,7 @@
#include "threads/Thread.h" #include "threads/Thread.h"
#include "utils/StringUtils.h" #include "utils/StringUtils.h"
#include "CompileInfo.h" #include "CompileInfo.h"
#include "utils/TimeUtils.cpp"


static const char* const levelNames[] = static const char* const levelNames[] =
{"DEBUG", "INFO", "NOTICE", "WARNING", "ERROR", "SEVERE", "FATAL", "NONE"}; {"DEBUG", "INFO", "NOTICE", "WARNING", "ERROR", "SEVERE", "FATAL", "NONE"};
Expand Down Expand Up @@ -198,19 +199,31 @@ void CLog::PrintDebugString(const std::string& line)


bool CLog::WriteLogString(int logLevel, const std::string& logString) bool CLog::WriteLogString(int logLevel, const std::string& logString)
{ {
#if defined(TARGET_LINUX)
static const char* prefixFormat = "%02.2d:%02.2d:%02.2d %10.6f T:%" PRIu64" %7s: ";
#else
static const char* prefixFormat = "%02.2d:%02.2d:%02.2d T:%" PRIu64" %7s: "; static const char* prefixFormat = "%02.2d:%02.2d:%02.2d T:%" PRIu64" %7s: ";

#endif
std::string strData(logString); std::string strData(logString);
/* fixup newline alignment, number of spaces should equal prefix length */ /* fixup newline alignment, number of spaces should equal prefix length */
StringUtils::Replace(strData, "\n", "\n "); StringUtils::Replace(strData, "\n", "\n ");


int hour, minute, second; int hour, minute, second;
s_globals.m_platform.GetCurrentLocalTime(hour, minute, second); s_globals.m_platform.GetCurrentLocalTime(hour, minute, second);


#if defined(TARGET_LINUX)
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
float Now = now.tv_sec + now.tv_nsec * 1e-9;
#endif

strData = StringUtils::Format(prefixFormat, strData = StringUtils::Format(prefixFormat,
hour, hour,
minute, minute,
second, second,
#if defined(TARGET_LINUX)
Now,
#endif
(uint64_t)CThread::GetCurrentThreadId(), (uint64_t)CThread::GetCurrentThreadId(),
levelNames[logLevel]) + strData; levelNames[logLevel]) + strData;


Expand Down

0 comments on commit 441217d

Please sign in to comment.