From e94d9893b8753e72adb92b2c5eb203830ddf641c Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Jul 2007 01:39:22 +0000 Subject: Moved to GPLv3 and Qt4, Changed String -> QString, other minor fixes git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@23 6ecfd1a5-f3ed-3746-8530-beee90d26b22 --- pokemod/Debug.cpp | 92 +++++++++++++++++++++++++++---------------------------- 1 file changed, 45 insertions(+), 47 deletions(-) (limited to 'pokemod/Debug.cpp') diff --git a/pokemod/Debug.cpp b/pokemod/Debug.cpp index 8790f13c..6cf6c98e 100644 --- a/pokemod/Debug.cpp +++ b/pokemod/Debug.cpp @@ -6,78 +6,76 @@ // Created: Wed Feb 14 23:44:39 2007 // Copyright: ©2007 Nerdy Productions // Licence: -// This program is free software; you can redistribute it and/or modify +// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or +// the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License along -// with this program; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// with this program. If not, see . ///////////////////////////////////////////////////////////////////////////// #include "Debug.h" -PokeGen::PokeMod::Log::~Log() -{ - flog.close(); -} - - -void PokeGen::PokeMod::Log::Write(const char *msg, const unsigned l) +PokeGen::PokeMod::Log::~Log() { -#ifdef PM_DEBUG + flog.close(); +} + +void PokeGen::PokeMod::Log::Write(const QString &msg, const unsigned l) +{ +#ifdef PM_DEBUG // Actual strings of the debugging levels const char *PokeModDebugStr[8] = {"Emergency", "Alert", "Critical Error", "Error", "Warning", "Notice", "Info", "Debug"}; // Only log if wanted if (l & level) { // Get the current time - char path[21]; - char time[9]; - short word = 0; - unsigned short temp = l; - while (temp >>= 1) + QString path(QDate::currentDate().toString("yyyy/MM-MMM/dd-ddd")); + QString time(QTime::currentTime().toString("hh:mm:ss.zzz")); + short word = 0; + unsigned short temp = l; + while (temp >>= 1) ++word; - time_t rawTime = std::time(NULL); - tm *curTime = std::localtime(&rawTime); - strftime(path, 21, "%y/%m-%b/%d-%a", curTime); - if (lastDay != path) - { - if (flog.is_open()) - flog.close(); - flog.open(String(PM_DEF_DIR ".pokegen" PM_DEF_SEP "log" PM_DEF_SEP "pokemod" PM_DEF_SEP "%s.log", path), std::ios::app); + if (lastDay != path) + { + if (flog.isOpen()) + flog.close(); + flog.setFileName(QString(PM_DEF_DIR ".pokegen" PM_DEF_SEP "log" PM_DEF_SEP "pokemod" PM_DEF_SEP "%1.log").arg(path)); + flog.open(QIODevice::Append); } - strftime(time, 9, "%X", curTime); // Get the actual output message - String output("%s (%s): %s", PokeModDebugStr[word], time, msg); - String validate("%s: %s", PokeModDebugStr[word], time, msg); - // Output to the command window + QString output = QString("%1 (%2): %3").arg(PokeModDebugStr[word]).arg(time).arg(msg); + QString validate = QString("%1: %2").arg(PokeModDebugStr[word]).arg(msg); + // Output to the command window if (consoleOutput) - std::cout << output << std::endl; - // Output to other streams (if wanted) - if (useOtherOutput && otherOutput->good()) - *otherOutput << output << std::endl; - if ((l & PM_DEBUG_VALIDATION) && useOtherOutputV && otherOutputV->good()) - *otherOutputV << validate << std::endl; - if (fileOutput) - { + console << output << endl; + // Output to other streams (if wanted) + if (useOtherOutput && !otherOutput->status()) + *otherOutput << output << endl; + if ((l & PM_DEBUG_VALIDATION) && useOtherOutputV && !otherOutputV->status()) + *otherOutputV << validate << endl; + if (fileOutput) + { // Output errors if the file fails - if (!flog) + if (flog.error()) { - if (consoleOutput) - std::cout << "Alert (" << curTime << "): Unable to open log file!" << std::endl; - if (useOtherOutput && otherOutput->good()) - *otherOutput << "Alert (" << curTime << "): Unable to open log file!" << std::endl; + if (consoleOutput) + console << "Alert (" << QTime::currentTime().toString("hh:mm:ss.zzz") << "): Unable to open log file!" << endl; + if (useOtherOutput && !otherOutput->status()) + *otherOutput << "Alert (" << QTime::currentTime().toString("hh:mm:ss.zzz") << "): Unable to open log file!" << endl; } else - flog << output << '\n'; - } - } + { + QTextStream temp(&flog); + temp << output << "\n"; + } + } + } #endif } -- cgit