diff --git a/samples/blackgui2/main.cpp b/samples/blackgui2/main.cpp index 8a422edda..c3254ba7f 100644 --- a/samples/blackgui2/main.cpp +++ b/samples/blackgui2/main.cpp @@ -3,6 +3,7 @@ #include "guimodeenums.h" #include "blackcore/blackcorefreefunctions.h" #include "blackmisc/blackmiscfreefunctions.h" +#include "blackmisc/loghandler.h" #include #include #include @@ -33,6 +34,7 @@ int main(int argc, char *argv[]) // app QApplication a(argc, argv); + BlackMisc::CLogHandler::instance()->install(); a.installTranslator(&translator); // modes diff --git a/samples/cli_client/main.cpp b/samples/cli_client/main.cpp index 97aca8649..fa7c6fbd3 100644 --- a/samples/cli_client/main.cpp +++ b/samples/cli_client/main.cpp @@ -4,6 +4,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "blackcore/network_vatlib.h" +#include "blackmisc/loghandler.h" #include "client.h" #include "reader.h" #include @@ -12,6 +13,7 @@ int main(int argc, char *argv[]) { QCoreApplication app (argc, argv); + BlackMisc::CLogHandler::instance()->install(); Client client(&app); LineReader reader; diff --git a/samples/voiceclient/main.cpp b/samples/voiceclient/main.cpp index cfe69fdc1..ccf3d843b 100644 --- a/samples/voiceclient/main.cpp +++ b/samples/voiceclient/main.cpp @@ -6,6 +6,7 @@ #include "blackcore/voice_vatlib.h" #include "blackcore/blackcorefreefunctions.h" #include "blackmisc/blackmiscfreefunctions.h" +#include "blackmisc/loghandler.h" #include "client.h" #include "reader.h" @@ -19,6 +20,7 @@ using namespace BlackMisc::Audio; int main(int argc, char *argv[]) { QCoreApplication app (argc, argv); + BlackMisc::CLogHandler::instance()->install(); Client client(&app); BlackMisc::registerMetadata(); BlackCore::registerMetadata(); diff --git a/src/blacksound/soundgenerator.cpp b/src/blacksound/soundgenerator.cpp index 1d573a100..c16f35266 100644 --- a/src/blacksound/soundgenerator.cpp +++ b/src/blacksound/soundgenerator.cpp @@ -502,16 +502,18 @@ namespace BlackSound void CSoundGenerator::printAllQtSoundDevices() { - qDebug() << "output"; + QTextStream qtout(stdout); + + qtout << "output" << endl; foreach(QAudioDeviceInfo qd, QAudioDeviceInfo::availableDevices(QAudio::AudioOutput)) { - qDebug() << qd.deviceName(); + qtout << qd.deviceName() << endl; } - qDebug() << "input"; + qtout << "input" << endl; foreach(QAudioDeviceInfo qd, QAudioDeviceInfo::availableDevices(QAudio::AudioInput)) { - qDebug() << qd.deviceName(); + qtout << qd.deviceName() << endl; } diff --git a/src/swiftcore/main.cpp b/src/swiftcore/main.cpp index 1ccb562d8..d28c47234 100644 --- a/src/swiftcore/main.cpp +++ b/src/swiftcore/main.cpp @@ -16,6 +16,7 @@ #include "blackmisc/networkutils.h" #include "blackmisc/blackmiscfreefunctions.h" #include "blackmisc/project.h" +#include "blackmisc/loghandler.h" #include #include #include @@ -31,6 +32,7 @@ int main(int argc, char *argv[]) { // metadata are registered in runtime QApplication a(argc, argv); // not QCoreApplication because of icon, http://qt-project.org/forums/viewthread/15412 + CLogHandler::instance()->install(); QIcon icon(BlackMisc::CIcons::swiftNova24()); QApplication::setWindowIcon(icon); QTextStream cin(stdin); diff --git a/src/swiftcore/tool.cpp b/src/swiftcore/tool.cpp index e6863360f..e15331899 100644 --- a/src/swiftcore/tool.cpp +++ b/src/swiftcore/tool.cpp @@ -3,6 +3,7 @@ #include "blackmisc/indexvariantmap.h" #include "blackmisc/avallclasses.h" #include "blackmisc/pqallquantities.h" +#include "blackmisc/loghandler.h" #include "blacksound/soundgenerator.h" #include @@ -36,9 +37,13 @@ namespace BlackMiscTest */ void Tool::serverLoop(BlackCore::CRuntime *runtime) { + CLogHandler::instance()->enableConsoleOutput(false); + Q_ASSERT(runtime); QThread::sleep(3); // let the DBus server startup - qDebug() << "Running on server here" << Tool::getPid() << "thread:" << QThread::currentThreadId(); + + QTextStream qtout(stdout); + qtout << "Running on server here " << Tool::getPid() << " thread: " << QThread::currentThreadId() << endl; // // Server loop @@ -52,145 +57,127 @@ namespace BlackMiscTest BlackCore::IContextSettings *settingsContext = runtime->getIContextSettings(); BlackCore::IContextOwnAircraft *ownAircraftContext = runtime->getIContextOwnAircraft(); - BlackCore::IContextApplication *applicationContext = runtime->getIContextApplication(); - - qDebug() << "-------------"; - qDebug() << "Connected with network: " << networkContext->isConnected(); - qDebug() << "Thread id:" << QThread::currentThreadId(); - qDebug() << "-------------"; - qDebug() << "x .. to exit 0 .. settings"; - qDebug() << "1 .. ATC booked 2 .. ATC online"; - qDebug() << "3 .. Aircrafts in range 4 .. my aircraft 5 .. voice rooms"; - qDebug() << "6 .. vatlib audio devices 7 .. Qt audio devices"; - qDebug() << "-------------"; - qDebug() << "oe . redirect enabled od . disable redirect"; - qDebug() << "-------------"; - qDebug() << "signal / slot logging:"; - qDebug() << "sig + context + [e]nabled/[d]isabled"; - qDebug() << "slo + context + [e]nabled/[d]isabled"; - qDebug() << "contexts: app / aud / net / own (aircraft) / set / sim / all"; - qDebug() << "examples: sigappd, slonete, slosimd, sloalle"; - qDebug() << "-------------"; + qtout << "-------------" << endl; + qtout << "Connected with network: " << networkContext->isConnected() << endl; + qtout << "Thread id: " << QThread::currentThreadId() << endl; + qtout << "-------------" << endl; + qtout << "x .. to exit 0 .. settings" << endl; + qtout << "1 .. ATC booked 2 .. ATC online" << endl; + qtout << "3 .. Aircrafts in range 4 .. my aircraft 5 .. voice rooms" << endl; + qtout << "6 .. vatlib audio devices 7 .. Qt audio devices" << endl; + qtout << "-------------" << endl; + qtout << "logging:" << endl; + qtout << "log + context + [e]nabled/[d]isabled" << endl; + qtout << "contexts: app / aud / net / own (aircraft) / set / sim / all" << endl; + qtout << "examples: logappd, lognete, logsimd, logalle" << endl; + qtout << "-------------" << endl; line = qtin.readLine().toLower().trimmed(); if (line.startsWith("0")) { - qDebug() << "-------------"; + qtout << "-------------" << endl; QString ret1; QMetaObject::invokeMethod(settingsContext, "getSettingsFileName", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QString, ret1)); - qDebug() << "Settings:" << ret1; + qtout << "Settings: " << ret1 << endl; QMetaObject::invokeMethod(settingsContext, "getSettingsAsJsonString", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QString, ret1)); - qDebug() << "JSON" << ret1; + qtout << "JSON " << ret1 << endl; } else if (line.startsWith("1")) { // remarks: use fully qualified name in Q_RETURN_ARG - qDebug() << "-------------"; - qDebug() << "ATC booked"; + qtout << "-------------" << endl; + qtout << "ATC booked" << endl; CAtcStationList stations; QMetaObject::invokeMethod(networkContext, "getAtcStationsBooked", Qt::BlockingQueuedConnection, Q_RETURN_ARG(BlackMisc::Aviation::CAtcStationList, stations)); - qDebug() << stations; + qtout << stations << endl; } else if (line.startsWith("2")) { - qDebug() << "-------------"; - qDebug() << "ATC online"; + qtout << "-------------" << endl; + qtout << "ATC online" << endl; CAtcStationList stations; QMetaObject::invokeMethod(networkContext, "getAtcStationsOnline", Qt::BlockingQueuedConnection, Q_RETURN_ARG(BlackMisc::Aviation::CAtcStationList, stations)); - qDebug() << stations; + qtout << stations << endl; } else if (line.startsWith("3")) { - qDebug() << "-------------"; - qDebug() << "aircrafts in range"; + qtout << "-------------" << endl; + qtout << "aircrafts in range" << endl; CAircraftList aircrafts; QMetaObject::invokeMethod(networkContext, "getAircraftsInRange", Qt::BlockingQueuedConnection, Q_RETURN_ARG(BlackMisc::Aviation::CAircraftList, aircrafts)); - qDebug() << aircrafts; + qtout << aircrafts << endl; } else if (line.startsWith("4")) { - qDebug() << "-------------"; - qDebug() << "my aircraft"; + qtout << "-------------" << endl; + qtout << "my aircraft" << endl; CAircraft aircraft; QMetaObject::invokeMethod(ownAircraftContext, "getOwnAircraft", Qt::BlockingQueuedConnection, Q_RETURN_ARG(BlackMisc::Aviation::CAircraft, aircraft)); - qDebug() << aircraft; + qtout << aircraft << endl; } else if (line.startsWith("5")) { - qDebug() << "-------------"; - qDebug() << "voice rooms"; + qtout << "-------------" << endl; + qtout << "voice rooms" << endl; CVoiceRoomList voiceRooms; QMetaObject::invokeMethod(audioContext, "getComVoiceRooms", Qt::BlockingQueuedConnection, Q_RETURN_ARG(BlackMisc::Audio::CVoiceRoomList, voiceRooms)); - qDebug() << voiceRooms; + qtout << voiceRooms << endl; } else if (line.startsWith("6")) { - qDebug() << "-------------"; - qDebug() << "vatlib audio devices"; + qtout << "-------------" << endl; + qtout << "vatlib audio devices" << endl; CAudioDeviceList devices; QMetaObject::invokeMethod(audioContext, "getAudioDevices", Qt::BlockingQueuedConnection, Q_RETURN_ARG(BlackMisc::Audio::CAudioDeviceList, devices)); - qDebug() << devices; + qtout << devices << endl; } else if (line.startsWith("7")) { - qDebug() << "-------------"; - qDebug() << "Qt audio devices"; + qtout << "-------------" << endl; + qtout << "Qt audio devices" << endl; BlackSound::CSoundGenerator::printAllQtSoundDevices(); } - else if (line.startsWith("oe")) + else if (line.startsWith("log")) { - applicationContext->setOutputRedirectionLevel(IContextApplication::RedirectAllOutput); - applicationContext->setStreamingForRedirectedOutputLevel(IContextApplication::RedirectAllOutput); - } - else if (line.startsWith("od")) - { - applicationContext->setOutputRedirectionLevel(IContextApplication::RedirectNone); - applicationContext->setStreamingForRedirectedOutputLevel(IContextApplication::RedirectNone); - } - else if (line.startsWith("sig")) - { - line.replace("signal", ""); - line.replace("sig", ""); + line.replace("log", ""); bool enable = line.endsWith("e"); - if (line.startsWith("app")) runtime->signalLogForApplication(enable); - else if (line.startsWith("aud")) runtime->signalLogForAudio(enable); - else if (line.startsWith("net")) runtime->signalLogForNetwork(enable); - else if (line.startsWith("own")) runtime->signalLogForOwnAircraft(enable); - else if (line.startsWith("set")) runtime->signalLogForSettings(enable); - else if (line.startsWith("sim")) runtime->signalLogForSimulator(enable); - else if (line.startsWith("all")) runtime->signalLog(enable); - } - else if (line.startsWith("slo")) - { - line.replace("slot", ""); - line.replace("slo", ""); - bool enable = line.endsWith("e"); - if (line.startsWith("app")) runtime->slotLogForApplication(enable); - else if (line.startsWith("aud")) runtime->slotLogForAudio(enable); - else if (line.startsWith("net")) runtime->slotLogForNetwork(enable); - else if (line.startsWith("own")) runtime->slotLogForOwnAircraft(enable); - else if (line.startsWith("set")) runtime->slotLogForSettings(enable); - else if (line.startsWith("sim")) runtime->slotLogForSimulator(enable); - else if (line.startsWith("all")) runtime->slotLog(enable); + if (line.startsWith("all")) + { + BlackMisc::CLogHandler::instance()->enableConsoleOutput(enable); + } + else + { + QString category; + if (line.startsWith("app")) category = IContextApplication::getMessageCategory(); + else if (line.startsWith("aud")) category = IContextAudio::getMessageCategory(); + else if (line.startsWith("net")) category = IContextNetwork::getMessageCategory(); + else if (line.startsWith("own")) category = IContextOwnAircraft::getMessageCategory(); + else if (line.startsWith("set")) category = IContextSettings::getMessageCategory(); + else if (line.startsWith("sim")) category = IContextSimulator::getMessageCategory(); + if (! category.isEmpty()) + { + BlackMisc::CLogHandler::instance()->handlerForCategory(category)->enableConsoleOutput(enable); + } + } } } QCoreApplication::quit(); diff --git a/src/swiftgui_standard/main.cpp b/src/swiftgui_standard/main.cpp index df2dbd57c..e877da5e9 100644 --- a/src/swiftgui_standard/main.cpp +++ b/src/swiftgui_standard/main.cpp @@ -7,6 +7,7 @@ #include "blacksim/blacksimfreefunctions.h" #include "blackmisc/blackmiscfreefunctions.h" #include "blackmisc/icons.h" +#include "blackmisc/loghandler.h" #include #include @@ -41,6 +42,7 @@ int main(int argc, char *argv[]) // application QApplication a(argc, argv); + CLogHandler::instance()->install(); QIcon icon(BlackMisc::CIcons::swift24()); QApplication::setWindowIcon(icon); const QString s = CStyleSheetUtility::instance().styles( diff --git a/src/swiftgui_standard/mainwindow.cpp b/src/swiftgui_standard/mainwindow.cpp index 532d98dee..c494f8fcc 100644 --- a/src/swiftgui_standard/mainwindow.cpp +++ b/src/swiftgui_standard/mainwindow.cpp @@ -297,6 +297,9 @@ bool MainWindow::isContextAudioAvailableCheck() */ void MainWindow::ps_displayStatusMessageInGui(const CStatusMessage &statusMessage) { + if (statusMessage.isRedundant()) return; + if (statusMessage.getSeverity() == CStatusMessage::SeverityDebug) return; + if (!this->m_init) return; this->ui->sb_MainStatusBar->show(); this->m_timerStatusBar->start(3000); @@ -307,19 +310,10 @@ void MainWindow::ps_displayStatusMessageInGui(const CStatusMessage &statusMessag this->ui->comp_MainInfoArea->getLogComponent()->appendStatusMessageToList(statusMessage); // display overlay for errors, but not for validation - if (statusMessage.getSeverity() == CStatusMessage::SeverityError && statusMessage.getType() != CStatusMessage::TypeValidation) - this->m_compInfoWindow->displayStatusMessage(statusMessage); -} - -/* - * Display a status message - */ -void MainWindow::ps_displayStatusMessagesInGui(const CStatusMessageList &messages) -{ - if (!this->m_init || messages.isEmpty()) return; - foreach(CStatusMessage msg, messages) + // TODO smarter use of CLogCategoryHandler to dispatch different categories of message to different MainWindow slots + if (statusMessage.getSeverity() == CStatusMessage::SeverityError && ! statusMessage.getCategory().endsWith(".validation")) { - this->ps_displayStatusMessageInGui(msg); + this->m_compInfoWindow->displayStatusMessage(statusMessage); } } diff --git a/src/swiftgui_standard/mainwindow.h b/src/swiftgui_standard/mainwindow.h index 83a4b6ab7..cfa088a7b 100644 --- a/src/swiftgui_standard/mainwindow.h +++ b/src/swiftgui_standard/mainwindow.h @@ -182,10 +182,7 @@ private slots: bool ps_reloadOwnAircraft(); //! Display status message - void ps_displayStatusMessageInGui(const BlackMisc::CStatusMessage &sendStatusMessage); - - //! Display status messages - void ps_displayStatusMessagesInGui(const BlackMisc::CStatusMessageList &messages); + void ps_displayStatusMessageInGui(const BlackMisc::CStatusMessage &); //! Settings have been changed void ps_onChangedSetttings(uint typeValue); diff --git a/src/swiftgui_standard/mainwindow_init.cpp b/src/swiftgui_standard/mainwindow_init.cpp index 128651fbe..5183c90dc 100644 --- a/src/swiftgui_standard/mainwindow_init.cpp +++ b/src/swiftgui_standard/mainwindow_init.cpp @@ -21,6 +21,7 @@ #include "blackmisc/avselcal.h" #include "blackmisc/project.h" #include "blackmisc/hotkeyfunction.h" +#include "blackmisc/loghandler.h" #include "blackmisc/logmessage.h" #include #include @@ -110,6 +111,10 @@ void MainWindow::init(const CRuntimeConfig &runtimeConfig) this->connect(this->ui->comp_MainInfoArea->getSettingsComponent(), &CSettingsComponent::changedAircraftsUpdateInterval, this->ui->comp_MainInfoArea->getAircraftComponent(), &CAircraftComponent::setUpdateIntervalSeconds); this->connect(this->ui->comp_MainInfoArea->getSettingsComponent(), &CSettingsComponent::changedAtcStationsUpdateInterval, this->ui->comp_MainInfoArea->getAtcStationComponent(), &::CAtcStationComponent::setUpdateIntervalSeconds); + // log messages + this->connect(CLogHandler::instance(), &CLogHandler::localMessageLogged, this, &MainWindow::ps_displayStatusMessageInGui); + this->connect(CLogHandler::instance(), &CLogHandler::remoteMessageLogged, this, &MainWindow::ps_displayStatusMessageInGui); + Q_ASSERT(connect); Q_UNUSED(connect); // suppress GCC warning in release build