Пример #1
0
Файл: log.cpp Проект: Thalur/ak
void LogAppend(ELogLevel aLogLevel, const char* aFile, const std::string& aFunc,
               const std::string& aMessage, int aLine, ...)
{
   if (!loggerInitialized && !uninitializedLoggerUseReported) {
      uninitializedLoggerUseReported = true;
      std::cout << "WARNING: Logger used without initialization. Call InitLogFile() first!" << std::endl;
   }

   // Remove the path from the filename
   aFile = RemovePath(aFile);

   // Assemble the user-generated message
   char buffer[510];
   va_list args;
   va_start(args, aLine);
#ifdef AK_SYSTEM_WINDOWS
   vsnprintf_s(buffer, 500, _TRUNCATE, aMessage.c_str(), args);
#else
   vsnprintf(buffer, 500, aMessage.c_str(), args);
#endif
   va_end(args);

   CClock now;
   std::string timestamp(now.GetTimeLong());
   if (loggerInitialized && aLogLevel >= fileLogLevel) {
      WriteLogEntry(*logFile, timestamp, GetLevelString(aLogLevel), aFile, aFunc, aLine, buffer);
   }
   if (aLogLevel >= consoleLogLevel) {
#ifdef AK_SYSTEM_ANDROID
         __android_log_print(ANDROID_LOG_DEBUG + static_cast<int32_t>(aLogLevel), appName.c_str(), buffer);
#else
      if (simplifiedConsoleOutput) {
         std::cout << buffer << std::endl;
      } else {
         WriteLogEntry(std::cout, timestamp, GetLevelString(aLogLevel), aFile, aFunc, aLine, buffer);
      }
#endif
   }
}