1 #include "Logging.h" 2 3 4 #ifdef WIN32 5 #include "windows.h" 6 #endif 7 8 /// TODO's 9 /// - Nested log entris 10 /// - Time 11 /// - Setting a log view level 12 13 14 namespace SyntopiaCore { 15 namespace Logging { 16 QVector<Logger*> Logger::loggers; 17 QStack<QTime> Logger::timeStack; 18 QStack<QString> Logger::timeStringStack; 19 LOG(QString message,LogLevel priority)20 void LOG(QString message, LogLevel priority) { 21 22 // On Windows this allows us to see debug in the Output::Debug window while running. 23 #ifdef WIN32 24 OutputDebugStringW((LPCWSTR) (message+"\r\n").utf16()); 25 #endif 26 27 for (int i = 0; i < Logger::loggers.size(); i++) { 28 Logger::loggers[i]->log(message, priority); 29 } 30 } 31 32 /// Useful aliases Debug(QString text)33 void Debug(QString text) { LOG(text, DebugLevel); } INFO(QString text)34 void INFO(QString text) { LOG(text, InfoLevel); } WARNING(QString text)35 void WARNING(QString text) { LOG(text, WarningLevel); } CRITICAL(QString text)36 void CRITICAL(QString text) { LOG(text, CriticalLevel); } 37 TIME(QString text)38 void TIME(QString text) { 39 LOG(text, TimingLevel); 40 41 Logger::timeStack.push(QTime::currentTime()); 42 Logger::timeStringStack.push(text); 43 } ; 44 TIME(int repetitions)45 void TIME(int repetitions) { 46 QTime t = Logger::timeStack.pop(); 47 QString s = Logger::timeStringStack.pop(); 48 int secs = t.msecsTo(QTime::currentTime()); 49 if (repetitions == 0) { 50 LOG(QString("Time: %1s for ").arg(secs/1000.0f) + s, TimingLevel); 51 } else { 52 LOG(QString("Time: %1s for %2. %3 repetitions, %4s per repetition.").arg(secs/1000.0f).arg(s) 53 .arg(repetitions).arg((secs/repetitions)/1000.0f), TimingLevel); 54 } 55 }; // End time... 56 57 58 59 } 60 } 61 62