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 16, 2016
1 parent 82d153d commit d25045f
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions xbmc/utils/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit d25045f

Please sign in to comment.