Ejemplo n.º 1
0
void Log::vprint(int logLevel, const TCHAR *fmt, va_list argList)
{
  Log *instance = getInstance();
  if (instance == 0) {
    return;
  }

  StringStorage timeString(_T("[Temporary unavaliable]"));
  SYSTEMTIME st;
  GetLocalTime(&st);
  timeString.format(_T("%.4d-%.2d-%.2d %.2d:%.2d:%.2d"),
                    st.wYear, st.wMonth, st.wDay,
                    st.wHour, st.wMinute, st.wSecond);

  const TCHAR logLevelSignature[] = _T("@!*+-:    xxxxxx");
  TCHAR sig = logLevelSignature[logLevel & 0x0F];

  int count = _vsctprintf(fmt, argList);
  TCHAR *formattedString = new TCHAR[count + 1];
  _vstprintf(formattedString, fmt, argList);

  StringStorage message;
  message.format(_T("[%4d] %s %c %s"),
                 GetCurrentThreadId(),
                 timeString.getString(),
                 sig,
                 formattedString);
  const TCHAR badCharacters[] = {13, 10, 0};
  message.removeChars(badCharacters, sizeof(badCharacters) / sizeof(TCHAR));
  delete[] formattedString;

  const TCHAR endLine[3] = {13, 10, 0};
  message.appendString(endLine);

  instance->flushLine(logLevel, message.getString());
}