QString Level::xml () { QString rv; rv.append(QString("<Level name=\"%1\">").arg(levelName())); QHashIterator<int, LevelObject*> o (this->levelObjects); o.toFront (); while (o.hasNext ()) { o.next (); LevelObject* obj = o.value (); int id = o.key (); rv.append(obj->xml (id)); } rv.append("</Level>"); return rv; }
int Logger::logx(int level, const char *fmt, va_list ap){ if(logger.log_level < level){ return 0; } char buf[LOG_BUF_LEN]; int len; char *ptr = buf; time_t time; struct timeval tv; struct tm *tm; gettimeofday(&tv, NULL); time = tv.tv_sec; tm = localtime(&time); /* %3ld 在数值位数超过3位的时候不起作用, 所以这里转成int */ len = sprintf(ptr, "%04d-%02d-%02d %02d:%02d:%02d.%03d ", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, (int)(tv.tv_usec/1000)); if(len < 0){ return -1; } ptr += len; memcpy(ptr, levelName(level), LEVEL_NAME_LEN); ptr += LEVEL_NAME_LEN; int space = sizeof(buf) - (ptr - buf) - 10; len = vsnprintf(ptr, space, fmt, ap); if(len < 0){ return -1; } ptr += len > space? space : len; *ptr++ = '\n'; *ptr = '\0'; len = ptr - buf; log_file.write(buf, len); log_file.flush(); return len; }
void LevelLoader::loadOldStyleLevel() { // Selecting the correct level m_level++; // Loading the levelset QString path = QStringLiteral("levelsets/%1.levelset").arg(m_levelname); path = QStandardPaths::locate(QStandardPaths::AppDataLocation, path); KConfig file(path, KConfig::SimpleConfig); QString levelName(QLatin1String("level") + QString::number(m_level)); if (!file.hasGroup(levelName)) { // No more levels or no levels found return; } // Loading level information KConfigGroup lvl = file.group(levelName); // add bricks int y = 1; QString key(QLatin1String("line") + QString::number(y)); while (lvl.hasKey(key)) { // one line of bricks to be converted QString line = lvl.readEntry(key, "error"); if (line == QLatin1String("error")) { qCritical() << "Something strange happened!!\n"; return; } qCDebug(KBREAKOUT_General) << line << endl; if (line.size() > WIDTH) { qCritical() << "Invalid file: too many bricks\n"; } emit newLine(line, y); ++y; key = QLatin1String("line") + QString::number(y); } // add gifts for (int i = 0; i < GIFT_TYPES_COUNT; ++i) { key = GIFT_TYPES[i]; if (!lvl.hasKey(key)) { continue; } QString line = lvl.readEntry(key, "error"); if (line == QLatin1String("error")) { qCritical() << "Impossible reading " << m_level << ":" << key << endl; return; } bool ok; int times = line.toInt(&ok); if (!ok) { qCritical() << m_levelname << ":" << key << " invalid number!!" << endl; continue; } emit newGift(key, times, QString()); } }
// spark::StreamLogHandler void spark::StreamLogHandler::logMessage(const char *msg, LogLevel level, const char *category, const LogAttributes &attr) { char buf[16]; // Timestamp if (attr.has_time) { snprintf(buf, sizeof(buf), "%010u ", (unsigned)attr.time); write(buf); } // Category if (category) { write("["); write(category); write("] "); } // Source file if (attr.has_file) { // Strip directory path const char *s = extractFileName(attr.file); write(s); // File name if (attr.has_line) { write(":"); snprintf(buf, sizeof(buf), "%d", attr.line); // Line number write(buf); } if (attr.has_function) { write(", "); } else { write(": "); } } // Function name if (attr.has_function) { // Strip argument and return types for better readability size_t n = 0; const char *s = extractFuncName(attr.function, &n); write(s, n); write("(): "); } // Level write(levelName(level)); write(": "); // Message if (msg) { write(msg); } // Additional attributes if (attr.has_code || attr.has_details) { write(" ["); if (attr.has_code) { write("code"); write(" = "); snprintf(buf, sizeof(buf), "%" PRIiPTR, attr.code); write(buf); } if (attr.has_details) { if (attr.has_code) { write(", "); } write("details"); write(" = "); write(attr.details); } write("]"); } write("\r\n"); }