Skip to content
Permalink
Browse files

logging: Add microsecond timer to log messages

  • Loading branch information...
popcornmix committed Dec 14, 2013
1 parent 025f98e commit 441217d8871c0588fc739897d1706a6747889e85
Showing with 15 additions and 2 deletions.
  1. +15 −2 xbmc/utils/log.cpp
@@ -24,6 +24,7 @@
#include "threads/Thread.h"
#include "utils/StringUtils.h"
#include "CompileInfo.h"
#include "utils/TimeUtils.cpp"

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

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: ";

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

int 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,
hour,
minute,
second,
#if defined(TARGET_LINUX)
Now,
#endif
(uint64_t)CThread::GetCurrentThreadId(),
levelNames[logLevel]) + strData;

0 comments on commit 441217d

Please sign in to comment.
You can’t perform that action at this time.