Beispiel #1
0
void FLog::Log(FLogLevels logLevel, const char *format, ... ) {
    if(!flogFile)
        return;

    //stop debug messages from being logged, unless compiler is told to log them
    #ifndef DEBUGLOG
    if(logLevel == FLOG_DEBUG)
        return;
    #endif

    //create formatted string message
    CStdString strData;
    va_list va;
    va_start(va, format);
    strData.FormatV(format,va);
    va_end(va);

    //get log level string name
    string levelName = levelNames[logLevel];

    //write to file
    fputs(levelName.c_str(), flogFile);
    fputs(": ", flogFile);
    fputs(strData, flogFile);
    fputs("\n", flogFile);
    //flush write buffer
    fflush(flogFile);
}
Beispiel #2
0
static void libass_log(int level, const char *fmt, va_list args, void *data)
{
  if(level >= 5)
    return;
  CStdString log;
  log.FormatV(fmt, args);
  CLog::Log(LOGDEBUG, "CDVDSubtitlesLibass: [ass] %s", log.c_str());
}
Beispiel #3
0
inline void PrintToStdOut(const char *strFormat, ...)
{
  CStdString strLog;

  va_list argList;
  va_start(argList, strFormat);
  strLog.FormatV(strFormat, argList);
  va_end(argList);

  CLockObject lock(g_outputMutex);
  cout << strLog << endl;
}
Beispiel #4
0
  void ILogger::Log(int loglevel, const char *format, ... )
  {
    CStdString strData;

    strData.reserve(16384);
    va_list va;
    va_start(va, format);
    strData.FormatV(format,va);
    va_end(va);

    log(loglevel, strData);
  }
Beispiel #5
0
void cThread::SetDescription(const char *Description, ...)
{
  free(description);
  description = NULL;
  if (Description)
  {
     va_list ap;
     va_start(ap, Description);
     CStdString desc;
     desc.FormatV(Description, ap);
     description = strdup(desc.c_str());
     va_end(ap);
  }
}
Beispiel #6
0
void CLog::DebugLog(const char *format, ... )
{
#ifdef _DEBUG
  CSingleLock waitLock(critSec);

  CStdString strData;
  strData.reserve(16384);

  va_list va;
  va_start(va, format);
  strData.FormatV(format, va);    
  va_end(va);
  
  OutputDebugString(strData.c_str());
  if( strData.Right(1) != "\n" )
    OutputDebugString("\n");
#endif
}
Beispiel #7
0
void CLibCEC::AddLog(const cec_log_level level, const char *strFormat, ...)
{
  CStdString strLog;

  va_list argList;
  va_start(argList, strFormat);
  strLog.FormatV(strFormat, argList);
  va_end(argList);

  CLibCEC *instance = CLibCEC::GetInstance();
  if (!instance)
    return;
  CLockObject lock(instance->m_mutex);

  cec_log_message message;
  message.level = level;
  message.time = GetTimeMs() - instance->m_iStartTime;
  snprintf(message.message, sizeof(message.message), "%s", strLog.c_str());

  if (instance->m_callbacks)
    instance->m_callbacks->CBCecLogMessage(instance->m_cbParam, message);
  else
    instance->m_logBuffer.Push(message);
}
Beispiel #8
0
void CLog::Log(int loglevel, const char *format, ... )
{
    if (g_advancedSettings.m_logLevel > LOG_LEVEL_NORMAL ||
            (g_advancedSettings.m_logLevel > LOG_LEVEL_NONE && loglevel >= LOGNOTICE))
    {
        CSingleLock waitLock(critSec);
        if (!fd)
        {
            // g_stSettings.m_logFolder is initialized in the CSettings constructor to Q:
            // and if we are running from DVD, it's changed to T: in CApplication::Create()
            CStdString strLogFile, strLogFileOld;

            strLogFile.Format("%sxbmc.log", _P(g_stSettings.m_logFolder).c_str());
            strLogFileOld.Format("%sxbmc.old.log", _P(g_stSettings.m_logFolder).c_str());

#ifndef _LINUX
            ::DeleteFile(strLogFileOld.c_str());
            ::MoveFile(strLogFile.c_str(), strLogFileOld.c_str());
#else
            ::unlink(strLogFileOld.c_str());
            ::rename(strLogFile.c_str(), strLogFileOld.c_str());
#endif

#ifndef _LINUX
            fd = _fsopen(strLogFile, "a+", _SH_DENYWR);
#else
            fd = fopen(strLogFile, "a+");
#endif
        }

        if (!fd)
            return ;

        SYSTEMTIME time;
        GetLocalTime(&time);

        MEMORYSTATUS stat;
        GlobalMemoryStatus(&stat);

        CStdString strPrefix, strData;

#ifdef __APPLE__
        strPrefix.Format("%02.2d:%02.2d:%02.2d T:%lu M:%9ju %7s: ", time.wHour, time.wMinute, time.wSecond, GetCurrentThreadId(), stat.dwAvailPhys, levelNames[loglevel]);
#else
        strPrefix.Format("%02.2d:%02.2d:%02.2d T:%lu M:%9u %7s: ", time.wHour, time.wMinute, time.wSecond, GetCurrentThreadId(), stat.dwAvailPhys, levelNames[loglevel]);
#endif

        strData.reserve(16384);
        va_list va;
        va_start(va, format);
        strData.FormatV(format,va);
        va_end(va);


        int length = 0;
        while ( length != (int)strData.length() )
        {
            length = strData.length();
            strData.TrimRight(" ");
            strData.TrimRight('\n');
            strData.TrimRight("\r");
        }

#if !defined(_LINUX) && (defined(_DEBUG) || defined(PROFILE))
        OutputDebugString(strData.c_str());
        OutputDebugString("\n");
#endif

        /* fixup newline alignment, number of spaces should equal prefix length */
        strData.Replace("\n", "\n                             ");
        strData += "\n";

        fwrite(strPrefix.c_str(), strPrefix.size(), 1, fd);
        fwrite(strData.c_str(), strData.size(), 1, fd);
        fflush(fd);
    }
#ifndef _LINUX
#if defined(_DEBUG) || defined(PROFILE)
    else
    {
        // In debug mode dump everything to devstudio regardless of level
        CSingleLock waitLock(critSec);
        CStdString strData;
        strData.reserve(16384);

        va_list va;
        va_start(va, format);
        strData.FormatV(format, va);
        va_end(va);

        OutputDebugString(strData.c_str());
        if( strData.Right(1) != "\n" )
            OutputDebugString("\n");

    }
#endif
#endif
}
Beispiel #9
0
void CLog::Log(int loglevel, const char *format, ... )
{
  if (g_advancedSettings.m_logLevel > LOG_LEVEL_NORMAL ||
     (g_advancedSettings.m_logLevel > LOG_LEVEL_NONE && loglevel >= LOGNOTICE))
  {
    CSingleLock waitLock(critSec);
    if (!m_file)
      return;

    SYSTEMTIME time;
    GetLocalTime(&time);

    MEMORYSTATUS stat;
    GlobalMemoryStatus(&stat);

    CStdString strPrefix, strData;

    strPrefix.Format("%02.2d:%02.2d:%02.2d T:%"PRIu64" M:%9"PRIu64" %7s: ", time.wHour, time.wMinute, time.wSecond, (uint64_t)CThread::GetCurrentThreadId(), (uint64_t)stat.dwAvailPhys, levelNames[loglevel]);

    strData.reserve(16384);
    va_list va;
    va_start(va, format);
    strData.FormatV(format,va);
    va_end(va);

    if (m_repeatLogLevel == loglevel && *m_repeatLine == strData)
    {
      m_repeatCount++;
      return;
    }
    else if (m_repeatCount)
    {
      CStdString strPrefix2, strData2;
      strPrefix2.Format("%02.2d:%02.2d:%02.2d T:%"PRIu64" M:%9"PRIu64" %7s: ", time.wHour, time.wMinute, time.wSecond, (uint64_t)CThread::GetCurrentThreadId(), (uint64_t)stat.dwAvailPhys, levelNames[m_repeatLogLevel]);

      strData2.Format("Previous line repeats %d times." LINE_ENDING, m_repeatCount);
      fwrite(strPrefix2.c_str(),strPrefix2.size(),1,m_file);
      fwrite(strData2.c_str(),strData2.size(),1,m_file);
#if !defined(_LINUX) && (defined(_DEBUG) || defined(PROFILE))
      OutputDebugString(strData2.c_str());
#endif
      m_repeatCount = 0;
    }
    
    *m_repeatLine     = strData;
    m_repeatLogLevel  = loglevel;

    unsigned int length = 0;
    while ( length != strData.length() )
    {
      length = strData.length();
      strData.TrimRight(" ");
      strData.TrimRight('\n');
      strData.TrimRight("\r");
    }

    if (!length)
      return;

#if !defined(_LINUX) && (defined(_DEBUG) || defined(PROFILE))
    OutputDebugString(strData.c_str());
    OutputDebugString("\n");
#endif

    /* fixup newline alignment, number of spaces should equal prefix length */
    strData.Replace("\n", LINE_ENDING"                                            ");
    strData += LINE_ENDING;

    fwrite(strPrefix.c_str(),strPrefix.size(),1,m_file);
    fwrite(strData.c_str(),strData.size(),1,m_file);
    fflush(m_file);
  }
#ifndef _LINUX
#if defined(_DEBUG) || defined(PROFILE)
  else
  {
    // In debug mode dump everything to devstudio regardless of level
    CSingleLock waitLock(critSec);
    CStdString strData;
    strData.reserve(16384);

    va_list va;
    va_start(va, format);
    strData.FormatV(format, va);
    va_end(va);

    OutputDebugString(strData.c_str());
    if( strData.Right(1) != "\n" )
      OutputDebugString("\n");

  }
#endif
#endif
}