Exemple #1
0
static inline string wbLogEntry_toJSON(wbLogEntry_t elem) {
  if (elem == NULL) {
    return "";
  } else if (WB_USE_JSON11) {
    json11::Json json = wbLogEntry_toJSONObject(elem);
    return json.string_value();
  } else {
    stringstream ss;

    ss << "{\n";
    ss << wbString_quote("id") << ":"
       << wbString_quote(wbLogEntry_getId(elem)) << ",\n";
    ss << wbString_quote("session_id") << ":"
       << wbString_quote(wbLogEntry_getSessionId(elem)) << ",\n";
    ss << wbString_quote("mpi_rank") << ":"
       << wbString(wbLogEntry_getMPIRank(elem)) << ",\n";
    ss << wbString_quote("level") << ":"
       << wbString_quote(getLevelName(wbLogEntry_getLevel(elem))) << ",\n";
    ss << wbString_quote("message") << ":"
       << wbString_quote(wbLogEntry_getMessage(elem)) << ",\n";
    ss << wbString_quote("file") << ":"
       << wbString_quote(wbLogEntry_getFile(elem)) << ",\n";
    ss << wbString_quote("function") << ":"
       << wbString_quote(wbLogEntry_getFunction(elem)) << ",\n";
    ss << wbString_quote("line") << ":" << wbLogEntry_getLine(elem)
       << ",\n";
    ss << wbString_quote("time") << ":" << wbLogEntry_getTime(elem)
       << "\n";
    ss << "}";

    return ss.str();
  }
  return "";
}
Exemple #2
0
void SLOG_LogMessage(SLOGLevel level, SLOGTopics tag, const char *format, ...)
{
  int logToConsole = (s_consoleFD != 0) && (level >= s_consoleLevel);
  int logToFile = (s_logFile != NULL) && (level >= s_fileLevel);

  if ( !(gDebugFlags & (1 << tag))) return;

  if(logToConsole || logToFile)
  {
    struct tm *localTime;
    time_t currentTime;
    va_list args;
    char buf[256];
    int size = 0;

    currentTime = time(NULL);
    localTime = localtime(&currentTime);

    /* print time, level and tag */
    size += snprintf(buf + size, sizeof(buf) - size, "%4d/%02d/%02d %02d:%02d:%02d %-7s [%-16s] ",
                     localTime->tm_year + 1900, localTime->tm_mon, localTime->tm_mday,
                     localTime->tm_hour, localTime->tm_min, localTime->tm_sec,
                     getLevelName(level), SLOGTags[tag]);

    /* print message */
    va_start(args, format);
    size += vsnprintf(buf + size, sizeof(buf) - size, format, args);
    va_end(args);

    if(size >= (int)sizeof(buf))
    {
      /* there were not enough space in the buf */
      size = sizeof(buf) - 1;
    }

    buf[size] = 0;

    if(logToConsole)
    {
      write(s_consoleFD, buf, size);
    }

    if(logToFile)
    {
      fputs(buf, s_logFile);
      fflush(s_logFile);
    }
#ifdef ENABLE_ASSERTS
    if (tag == DEBUG_TAG_ASSERTS)
    {
      abort();
    }
#endif
  }
}
Exemple #3
0
void wbLogger_append(wbLogLevel_t level, string msg, const char *file,
                     const char *fun, int line) {
  wbLogEntry_t elem;
  wbLogger_t logger;

  wb_init(NULL, NULL);

  logger = _logger;

  if (wbLogger_getLevel(logger) < level) {
    return;
  }

  elem = wbLogEntry_initialize(level, msg, file, fun, line);

#ifdef wbLogger_printOnLog
  if (wbLogger_printOnLog) {
    if (level <= wbLogger_getLevel(logger) && elem) {
      json11::Json json = json11::Json::object{
          {"type", "logger"},
          {"id", wbLogEntry_getId(elem)},
          {"session_id", wbLogEntry_getSessionId(elem)},
          {"data", wbLogEntry_toJSONObject(elem)}};
      std::cout << json.dump() << std::endl;
    }
  }
#endif /* wbLogger_printOnLog */

  if (wbLogger_getHead(logger) == NULL) {
    wbLogger_setHead(logger, elem);
  } else {
    wbLogEntry_t prev = wbLogger_getHead(logger);

    while (wbLogEntry_hasNext(prev)) {
      prev = wbLogEntry_getNext(prev);
    }
    wbLogEntry_setNext(prev, elem);
  }

#if 0
  if (level <= wbLogger_getLevel(logger) && elem) {
    const char *levelName = getLevelName(level);

    fprintf(stderr, "= LOG: %s: %s (In %s:%s on line %d). =\n", levelName,
            wbLogEntry_getMessage(elem), wbLogEntry_getFile(elem),
            wbLogEntry_getFunction(elem), wbLogEntry_getLine(elem));
  }
#endif

  wbLogger_incrementLength(logger);

  return;
}
Exemple #4
0
static inline json11::Json wbLogEntry_toJSONObject(wbLogEntry_t elem) {
  json11::Json json = json11::Json::object{
      {"id", wbLogEntry_getId(elem)},
      {"session_id", wbLogEntry_getSessionId(elem)},
      {"mpi_rank", wbLogEntry_getMPIRank(elem)},
      {"level", getLevelName(wbLogEntry_getLevel(elem))},
      {"file", wbLogEntry_getFile(elem)},
      {"function", wbLogEntry_getFunction(elem)},
      {"line", wbLogEntry_getLine(elem)},
      {"time", wbLogEntry_getTime(elem)},
      {"message", wbLogEntry_getMessage(elem)},
  };
  return json;
}
Exemple #5
0
/**
 * Log a message to the logging stream (usually a file).
 * @param level error level (see LOG_LEVELS enum).
 * @param msg message to be logged.
 */
void logMessage(const int level, const char* msg) {
    char aux[BUFSIZ];
    const time_t t = time(NULL);

    if ((LOG_LEVEL & level) != level) {
        return;
    }

    snprintf(aux, sizeof(aux), "%.24s %s\t%s\n", ctime(&t),
            getLevelName(level), msg);

    fprintf(logStream, "%s", aux);
    fflush(logStream);
}
Exemple #6
0
Factor::operator SEXP() {
    int numObs = getNumObservations();
    int numLevels = getNumLevels();
    Rcpp::IntegerVector iv(numObs); // allocates R memory
    Rcpp::CharacterVector cv(numLevels); // ditto
    SEXP RFactor = iv;
    for(int i=0; i < numObs; ++i)
	iv[i] = getObservedLevelNum(i);
    for(int i=0; i < numLevels; ++i)
	cv[i] = getLevelName(i);
    Rcpp::RObject ro(RFactor);
    ro.attr("class") = "factor";
    ro.attr("levels") = cv;
    return ro;
}
void LevelManager::setLevel(int levelNumber)
{
	std::string levelName = getLevelName(levelNumber);
	std::string levelPath = getLevelPath(levelNumber);

	if (rgl::FileIO::fileExists(levelPath + levelName + ".tmx"))
	{
		rgl::Game::get()->getGameStateMachine()->changeState(std::make_shared<EditState>(levelPath, levelName + ".tmx"));
		m_currentLevel = levelNumber;
	}
	else
	{
		rgl::Game::get()->getGameStateMachine()->changeState(std::make_shared<MainMenu>());
		m_currentLevel = 0;
	}
}
Exemple #8
0
static inline string wbLogEntry_toJSON(wbLogEntry_t elem) {
  if (elem != NULL) {
    stringstream ss;

    ss << "{\n";
    ss << wbString_quote("level") << ":"
       << wbString_quote(getLevelName(wbLogEntry_getLevel(elem))) << ",\n";
    ss << wbString_quote("message") << ":"
       << wbString_quote(wbLogEntry_getMessage(elem)) << ",\n";
    ss << wbString_quote("file") << ":"
       << wbString_quote(wbLogEntry_getFile(elem)) << ",\n";
    ss << wbString_quote("function") << ":"
       << wbString_quote(wbLogEntry_getFunction(elem)) << ",\n";
    ss << wbString_quote("line") << ":" << wbLogEntry_getLine(elem) << ",\n";
    ss << wbString_quote("time") << ":" << wbLogEntry_getTime(elem) << "\n";
    ss << "}";

    return ss.str();
  }
  return "";
}
Exemple #9
0
void wbLogger_append(wbLogLevel_t level, string msg, const char *file,
                     const char *fun, int line) {
  wbLogEntry_t elem;
  wbLogger_t logger;

  wb_init();

  logger = _logger;

  if (wbLogger_getLevel(logger) < level) {
    return;
  }

  elem = wbLogEntry_initialize(level, msg, file, fun, line);

  if (wbLogger_getHead(logger) == NULL) {
    wbLogger_setHead(logger, elem);
  } else {
    wbLogEntry_t prev = wbLogger_getHead(logger);

    while (wbLogEntry_hasNext(prev)) {
      prev = wbLogEntry_getNext(prev);
    }
    wbLogEntry_setNext(prev, elem);
  }

#if 0
  if (level <= wbLogger_getLevel(logger) && elem) {
    const char *levelName = getLevelName(level);

    fprintf(stderr, "= LOG: %s: %s (In %s:%s on line %d). =\n", levelName,
            wbLogEntry_getMessage(elem), wbLogEntry_getFile(elem),
            wbLogEntry_getFunction(elem), wbLogEntry_getLine(elem));
  }
#endif

  wbLogger_incrementLength(logger);

  return;
}
Exemple #10
0
/** Registers the currently displayed frame for making a screen shot.
 *
 *  The filename will be suffixed with a number, such that no files are
 *  overwritten.
 *
 *  \param path The directory path to save the screenshot in.
 */
void screenDumpToDisk(const char* path)
{
	unsigned int screendump_num = 0;
	time_t aclock;
	struct tm *t;

	time(&aclock);           /* Get time in seconds */
	t = localtime(&aclock);  /* Convert time to struct */

	ssprintf(screendump_filename, "%s/wz2100-%04d%02d%02d_%02d%02d%02d-%s.png", path, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, getLevelName());

        while (PHYSFS_exists(screendump_filename))
	{
		ssprintf(screendump_filename, "%s/wz2100-%04d%02d%02d_%02d%02d%02d-%s-%d.png", path, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, getLevelName(), ++screendump_num);
	}
	screendump_required = true;
}
Exemple #11
0
// call after swap buffers
void wzPerfFrame()
{
	if (!perfStarted)
	{
		return; // not started yet
	}
	ASSERT(queryActive == PERF_COUNT, "Missing wfPerfEnd() call");
	PERF_STORE store;
	for (int i = 0; i < PERF_COUNT; i++)
	{
		glGetQueryObjectui64v(perfpos[i], GL_QUERY_RESULT, &store.counters[i]);
	}
	glErrors();
	perfList.append(store);
	perfStarted = false;

	// Make a screenshot to document sample content
	time_t aclock;
	struct tm *t;

	time(&aclock);           /* Get time in seconds */
	t = localtime(&aclock);  /* Convert time to struct */

	ssprintf(screendump_filename, "screenshots/wz2100-perf-sample-%02d-%04d%02d%02d_%02d%02d%02d-%s.png", perfList.size() - 1, 
	         t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, getLevelName());
	screendump_required = true;
	GL_DEBUG("Performance sample complete");
}
void ConsoleLogDriver::setLogSettings() {
    CMDLineRegistry *cmd = AppContext::getCMDLineRegistry();
    if(cmd->hasParameter(CMDLineCoreOptions::LOG_FORMAT)) {
       QString logFormat = cmd->getParameterValue(CMDLineCoreOptions::LOG_FORMAT);
       settings.showLevel = logFormat.contains("L", Qt::CaseSensitive);
       settings.showCategory = logFormat.contains("C", Qt::CaseSensitive);
       settings.showDate = logFormat.contains(QRegExp("[M{2}Y{2,4}d{2}H{2}m{2}s{2}z{3}]"));
       settings.logPattern = logFormat;
    } else if(cmd->hasParameter( LOG_SHOW_DATE_CMD_OPTION ) || //old options
        cmd->hasParameter( LOG_SHOW_LEVEL_CMD_OPTION ) ||
        cmd->hasParameter( LOG_SHOW_CATEGORY_CMD_OPTION )){

        settings.logPattern = "";
        if (cmd->hasParameter( LOG_SHOW_DATE_CMD_OPTION )) {
            settings.showDate = true;
            settings.logPattern += "[hh:mm]";
        }
        if (cmd->hasParameter( LOG_SHOW_LEVEL_CMD_OPTION )) {
            settings.showLevel = true;
            settings.logPattern += "[L]";
        }
        if (cmd->hasParameter( LOG_SHOW_CATEGORY_CMD_OPTION )) {
            settings.showCategory = true;
            settings.logPattern += "[C]";
        }
    } else{
        settings.logPattern = "[hh:mm][L]";
    }

    QString logLevel;
    if(cmd->hasParameter(CMDLineCoreOptions::LOG_LEVEL)){
        logLevel = cmd->getParameterValue(CMDLineCoreOptions::LOG_LEVEL);
    } else if( cmd->hasParameter( LOG_LEVEL_NONE_CMD_OPTION ) ){
        logLevel = "NONE";
    } else if(cmd->hasParameter( LOG_LEVEL_ERROR_CMD_OPTION )) {
        logLevel = "ERROR";
    }else if( cmd->hasParameter( LOG_LEVEL_INFO_CMD_OPTION ) ) {
        logLevel = "INFO";
    } else if( cmd->hasParameter( LOG_LEVEL_DETAILS_CMD_OPTION ) ) {
        logLevel = "DETAILS";
    } else if( cmd->hasParameter( LOG_LEVEL_TRACE_CMD_OPTION ) ) {
        logLevel = "TRACE";
    }else {
        logLevel = "ERROR";
    }

    LogServer* ls = LogServer::getInstance();
    const QStringList& categoryList = ls->getCategories();
    logLevel = logLevel.remove(" ");
    QStringList cats = logLevel.split(QRegExp("[,=]"));

    LogCategories::init();
    if(cats.size() == 1) {
        int minLevel = 10;
        for (int i=0; i<LogLevel_NumLevels; i++) {
            if(getLevelName((LogLevel)i) == logLevel) {
                minLevel = i;
            }
        }
        for (int i=0; i<LogLevel_NumLevels; i++) {
            settings.activeLevelGlobalFlag[i] = (i >= minLevel);
        }
        foreach(const QString &str, categoryList) {
            LoggerSettings cs;
            cs.categoryName = str;
            for (int i=0; i<LogLevel_NumLevels; i++) {
                cs.activeLevelFlag[i] = (i >= minLevel);
            }
            settings.categories[str] = cs;
        }
Exemple #13
0
 void Logger::log(const LogLevel level, const std::string& message) const {
     getStream() << getLevelName(level) << ": " << message << std::endl;
 }
std::string LevelManager::getLevelPath(int levelNumber)
{
	return "assets/levels/" + getLevelName(levelNumber) + "/";
}