summaryrefslogtreecommitdiffstats
path: root/pokemod/Debug.cpp
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2007-07-03 04:20:36 +0000
committerBen Boeckel <MathStuf@gmail.com>2007-07-03 04:20:36 +0000
commit65cc463f1d91fe99acf1c4dd9bce7e0038593022 (patch)
tree95644c3c42a4a23db50dc42722cdeb4489427e14 /pokemod/Debug.cpp
parent9102febc37475af113681eaaee02ecc2ea04b4da (diff)
downloadsigen-65cc463f1d91fe99acf1c4dd9bce7e0038593022.tar.gz
sigen-65cc463f1d91fe99acf1c4dd9bce7e0038593022.tar.xz
sigen-65cc463f1d91fe99acf1c4dd9bce7e0038593022.zip
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
Diffstat (limited to 'pokemod/Debug.cpp')
-rw-r--r--pokemod/Debug.cpp98
1 files changed, 46 insertions, 52 deletions
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
+}