From 65cc463f1d91fe99acf1c4dd9bce7e0038593022 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Tue, 3 Jul 2007 04:20:36 +0000 Subject: Fixed Logging, minor fixes, got rid of NatureEffect, and started migration from wxGTK to Qt git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@22 6ecfd1a5-f3ed-3746-8530-beee90d26b22 --- pokemod/Debug.cpp | 98 ++++++++++++++++++++++++++----------------------------- 1 file changed, 46 insertions(+), 52 deletions(-) (limited to 'pokemod/Debug.cpp') diff --git a/pokemod/Debug.cpp b/pokemod/Debug.cpp index 389c3138..8790f13c 100644 --- a/pokemod/Debug.cpp +++ b/pokemod/Debug.cpp @@ -23,67 +23,61 @@ #include "Debug.h" -#ifdef PM_DEBUG - -#ifdef PG_DEBUG_WINDOW -extern debugWindow PokeModDebugWindow; -#endif - -int PokeModDebugLevel; - -void PokeGen::PokeMod::Log(const char *msg, const int level) +PokeGen::PokeMod::Log::~Log() +{ + flog.close(); +} + + +void PokeGen::PokeMod::Log::Write(const char *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 (level <= PokeModDebugLevel) + if (l & level) { // Get the current time char path[21]; - char time[9]; + char time[9]; + 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); + 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); + } strftime(time, 9, "%X", curTime); // Get the actual output message - String output("%s (%s): %s", PokeModDebugStr[level], time, msg); - // Output to the command window -# ifdef PM_DEBUG_OUTPUT_CONSOLE - std::cout << output << std::endl; -# endif - // Output to the debugging console -# ifdef PM_DEBUG_OUTPUT_DEBUG - if (PokeModDebugWindow.m_Show[level].IsChecked()) - PokeModDebugWindow.m_Debug.Append(output); -# endif - // Output to the debugging log -# ifdef PM_DEBUG_OUTPUT_FILE - std::ofstream flog(String("/log/pokemod/%s.log", path), std::ios::app); - // Output erros if the file fails - if (!flog) - { -# ifdef PM_DEBUG_OUTPUT_CONSOLE - std::cout << "Alert (" << curTime << "): Unable to open log file!\n"; -# endif -# ifdef PM_DEBUG_OUTPUT_DEBUG - PokeModDebugWindow.m_Debug.Append(String("Alert (%s): Unable to open log file!", curTime)); -# endif - } - else - { - flog << output << '\n'; - flog.close(); - } -# endif - } -} - -#else - -// Empty function if debugging isn't wanted -void PokeGen::PokeMod::Log(const String &msg, const int level) -{ - return; -} - + String output("%s (%s): %s", PokeModDebugStr[word], time, msg); + String validate("%s: %s", PokeModDebugStr[word], time, 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) + { + // Output errors if the file fails + if (!flog) + { + 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; + } + else + flog << output << '\n'; + } + } #endif +} -- cgit