| 1 |
/* |
| 2 |
* Copyright (C) 2013-2015, 2019 by the Konclude Developer Team. |
| 3 |
* |
| 4 |
* This file is part of the reasoning system Konclude. |
| 5 |
* For details and support, see <http://konclude.com/>. |
| 6 |
* |
| 7 |
* Konclude is free software: you can redistribute it and/or modify |
| 8 |
* it under the terms of version 3 of the GNU Lesser General Public |
| 9 |
* License (LGPLv3) as published by the Free Software Foundation. |
| 10 |
* |
| 11 |
* Konclude is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU (Lesser) General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU (Lesser) General Public |
| 17 |
* License along with Konclude. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
*/ |
| 20 |
#include "CConsolePrintLogObserver.h" |
| 21 |
|
| 22 |
namespace Konclude { |
| 23 |
|
| 24 |
namespace Logger { |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
CConsolePrintLogObserver::CConsolePrintLogObserver() { |
| 29 |
CLogger* logger = CLogger::getInstance(); |
| 30 |
CCallbackRequestLogMessagesContext* logMessagesContext = logger->getLogMessages(0,-1,0,100,QStringList(),QLinkedList<void*>()); |
| 31 |
foreach (CLogMessage* message, logMessagesContext->getLogMessages()) { |
| 32 |
postLogMessage(message); |
| 33 |
} |
| 34 |
logMessagesContext->releaseMessages(); |
| 35 |
} |
| 36 |
|
| 37 |
CConsolePrintLogObserver::~CConsolePrintLogObserver() { |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
void CConsolePrintLogObserver::postLogMessage(CLogMessage *message) { |
| 42 |
|
| 43 |
double logLevel = message->getLogLevel(); |
| 44 |
QString logLevelString; |
| 45 |
|
| 46 |
QString domainString = message->getDomain(); |
| 47 |
|
| 48 |
if (logLevel >= 90) { |
| 49 |
logLevelString = "error"; |
| 50 |
} else if (logLevel >= 80) { |
| 51 |
logLevelString = "error"; |
| 52 |
} else if (logLevel >= 70) { |
| 53 |
logLevelString = "error"; |
| 54 |
} else if (logLevel >= 60) { |
| 55 |
logLevelString = " warn "; |
| 56 |
} else if (logLevel >= 30) { |
| 57 |
logLevelString = " info "; |
| 58 |
} else { |
| 59 |
logLevelString = "notice"; |
| 60 |
} |
| 61 |
QString logString = QString("{%1} %2 [%3]>> %4\r\n").arg(logLevelString).arg(message->getDateTimeMSecString()).arg(message->getDomain()).arg(message->getMessage()); |
| 62 |
std::cout << logString.toLocal8Bit().data() << std::flush; |
| 63 |
|
| 64 |
|
| 65 |
#ifndef KONCLUDE_FORCE_ALL_DEBUG_DEACTIVATED |
| 66 |
QFile loggingFile(QString("./Debugging/logging.txt")); |
| 67 |
if (loggingFile.open(QIODevice::Append)) { |
| 68 |
QByteArray data = logString.toUtf8(); |
| 69 |
loggingFile.write(data); |
| 70 |
loggingFile.write("\r\n"); |
| 71 |
loggingFile.close(); |
| 72 |
} |
| 73 |
#endif |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
}; // end namespace Logger |
| 78 |
|
| 79 |
}; // end namespace Konclude |