| 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 |
|
| 21 |
#include "CConsolePrintConfigurableLogObserver.h" |
| 22 |
|
| 23 |
namespace Konclude { |
| 24 |
|
| 25 |
namespace Logger { |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
CConsolePrintConfigurableLogObserver::CConsolePrintConfigurableLogObserver(QStringList domainInfoList, double domainFilterLevel, bool printTime, bool printDomain, bool printMessage, bool printError) { |
| 30 |
confTime = printTime; |
| 31 |
confDomain = printDomain; |
| 32 |
confMessage = printMessage; |
| 33 |
confError = printError; |
| 34 |
mDomainFilterLevel = domainFilterLevel; |
| 35 |
|
| 36 |
foreach (QString domainString, domainInfoList) { |
| 37 |
domainInfoSet.insert(domainString); |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
CLogger* logger = CLogger::getInstance(); |
| 42 |
CCallbackRequestLogMessagesContext* logMessagesContext = logger->getLogMessages(0,-1,30,100,QStringList(),QLinkedList<void*>()); |
| 43 |
foreach (CLogMessage* message, logMessagesContext->getLogMessages()) { |
| 44 |
postLogMessage(message); |
| 45 |
} |
| 46 |
logMessagesContext->releaseMessages(); |
| 47 |
|
| 48 |
} |
| 49 |
|
| 50 |
CConsolePrintConfigurableLogObserver::~CConsolePrintConfigurableLogObserver() { |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
void CConsolePrintConfigurableLogObserver::postLogMessage(CLogMessage *message) { |
| 55 |
|
| 56 |
bool printMessage = true; |
| 57 |
|
| 58 |
|
| 59 |
double logLevel = message->getLogLevel(); |
| 60 |
QString logLevelString; |
| 61 |
|
| 62 |
QString domainString = message->getDomain(); |
| 63 |
|
| 64 |
if (logLevel >= 90) { |
| 65 |
logLevelString = "catastrophic error"; |
| 66 |
} else if (logLevel >= 80) { |
| 67 |
logLevelString = "exceptional error"; |
| 68 |
} else if (logLevel >= 70) { |
| 69 |
logLevelString = "error"; |
| 70 |
} else if (logLevel >= 60) { |
| 71 |
logLevelString = "warning"; |
| 72 |
} else if (logLevel >= 30) { |
| 73 |
logLevelString = "info"; |
| 74 |
} else { |
| 75 |
printMessage = false; |
| 76 |
logLevelString = "notice"; |
| 77 |
} |
| 78 |
|
| 79 |
bool filterMessage = false; |
| 80 |
if (logLevel < mDomainFilterLevel) { |
| 81 |
filterMessage = true; |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
if (filterMessage && logLevel >= 30) { |
| 86 |
printMessage = domainInfoSet.contains(domainString); |
| 87 |
} |
| 88 |
|
| 89 |
if (printMessage) { |
| 90 |
QString messageString; |
| 91 |
|
| 92 |
if (confError) { |
| 93 |
if (!messageString.isEmpty()) { |
| 94 |
messageString += QString(" "); |
| 95 |
} |
| 96 |
messageString += QString("{%1}").arg(logLevelString); |
| 97 |
} |
| 98 |
|
| 99 |
if (confTime) { |
| 100 |
if (!messageString.isEmpty()) { |
| 101 |
messageString += QString(" "); |
| 102 |
} |
| 103 |
messageString += QString(message->getTimeMSecString()); |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
if (confDomain) { |
| 108 |
if (!messageString.isEmpty()) { |
| 109 |
messageString += QString(" "); |
| 110 |
} |
| 111 |
messageString += QString("[%1]").arg(domainString); |
| 112 |
} |
| 113 |
|
| 114 |
if (confMessage) { |
| 115 |
if (!messageString.isEmpty()) { |
| 116 |
messageString += QString(" >> "); |
| 117 |
} |
| 118 |
messageString += QString("%1").arg(message->getMessage()); |
| 119 |
} |
| 120 |
|
| 121 |
std::cout << messageString.toLocal8Bit().data() << "\r\n"<<std::flush; |
| 122 |
|
| 123 |
#ifndef KONCLUDE_FORCE_ALL_DEBUG_DEACTIVATED |
| 124 |
QFile loggingFile(QString("./Debugging/logging.txt")); |
| 125 |
if (loggingFile.open(QIODevice::Append)) { |
| 126 |
QByteArray data = messageString.toUtf8(); |
| 127 |
loggingFile.write(data); |
| 128 |
loggingFile.write("\r\n"); |
| 129 |
loggingFile.close(); |
| 130 |
} |
| 131 |
#endif |
| 132 |
|
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
}; // end namespace Logger |
| 138 |
|
| 139 |
}; // end namespace Konclude |