refs #338 Using CLogPattern for subscribing to log messages and selectively enabling console output.

This commit is contained in:
Mathew Sutcliffe
2014-10-22 02:57:07 +01:00
parent 7f783fac8f
commit 8962368278
3 changed files with 11 additions and 13 deletions

View File

@@ -169,18 +169,18 @@ namespace BlackMiscTest
} }
else else
{ {
QString category; CLogCategoryList categories;
if (line.startsWith("app")) category = CLogCategoryList(applicationContext).back().toQString(); if (line.startsWith("app")) categories = applicationContext;
else if (line.startsWith("aud")) category = CLogCategoryList(audioContext).back().toQString(); else if (line.startsWith("aud")) categories = audioContext;
else if (line.startsWith("net")) category = CLogCategoryList(networkContext).back().toQString(); else if (line.startsWith("net")) categories = networkContext;
else if (line.startsWith("own")) category = CLogCategoryList(ownAircraftContext).back().toQString(); else if (line.startsWith("own")) categories = ownAircraftContext;
else if (line.startsWith("set")) category = CLogCategoryList(settingsContext).back().toQString(); else if (line.startsWith("set")) categories = settingsContext;
else if (line.startsWith("sim")) category = CLogCategoryList(simulatorContext).back().toQString(); else if (line.startsWith("sim")) categories = simulatorContext;
if (! category.isEmpty()) if (! categories.isEmpty())
{ {
BlackMisc::singleShot(0, BlackMisc::CLogHandler::instance()->thread(), [ = ]() BlackMisc::singleShot(0, BlackMisc::CLogHandler::instance()->thread(), [ = ]()
{ {
BlackMisc::CLogHandler::instance()->handlerForCategoryPrefix(category)->enableConsoleOutput(enable); BlackMisc::CLogHandler::instance()->handlerForPattern(CLogPattern::allOf(categories))->enableConsoleOutput(enable);
}); });
} }
} }

View File

@@ -298,7 +298,6 @@ bool MainWindow::isContextAudioAvailableCheck()
void MainWindow::ps_displayStatusMessageInGui(const CStatusMessage &statusMessage) void MainWindow::ps_displayStatusMessageInGui(const CStatusMessage &statusMessage)
{ {
if (statusMessage.isRedundant()) return; if (statusMessage.isRedundant()) return;
if (statusMessage.getSeverity() == CStatusMessage::SeverityDebug) return;
if (statusMessage.wasHandledBy(this)) return; if (statusMessage.wasHandledBy(this)) return;
statusMessage.markAsHandledBy(this); statusMessage.markAsHandledBy(this);
@@ -313,7 +312,6 @@ void MainWindow::ps_displayStatusMessageInGui(const CStatusMessage &statusMessag
this->ui->comp_MainInfoArea->getLogComponent()->appendStatusMessageToList(statusMessage); this->ui->comp_MainInfoArea->getLogComponent()->appendStatusMessageToList(statusMessage);
// display overlay for errors, but not for validation // display overlay for errors, but not for validation
// TODO smarter use of CLogCategoryHandler to dispatch different categories of message to different MainWindow slots
if (statusMessage.getSeverity() == CStatusMessage::SeverityError && ! statusMessage.getCategories().contains(CLogCategory::validation())) if (statusMessage.getSeverity() == CStatusMessage::SeverityError && ! statusMessage.getCategories().contains(CLogCategory::validation()))
{ {
this->m_compInfoWindow->displayStatusMessage(statusMessage); this->m_compInfoWindow->displayStatusMessage(statusMessage);

View File

@@ -112,8 +112,8 @@ void MainWindow::init(const CRuntimeConfig &runtimeConfig)
this->connect(this->ui->comp_MainInfoArea->getSettingsComponent(), &CSettingsComponent::changedAtcStationsUpdateInterval, this->ui->comp_MainInfoArea->getAtcStationComponent(), &::CAtcStationComponent::setUpdateIntervalSeconds); this->connect(this->ui->comp_MainInfoArea->getSettingsComponent(), &CSettingsComponent::changedAtcStationsUpdateInterval, this->ui->comp_MainInfoArea->getAtcStationComponent(), &::CAtcStationComponent::setUpdateIntervalSeconds);
// log messages // log messages
this->connect(CLogHandler::instance(), &CLogHandler::localMessageLogged, this, &MainWindow::ps_displayStatusMessageInGui); auto *logHandler = CLogHandler::instance()->handlerForPattern(CLogPattern().withSeverityAtOrAbove(CStatusMessage::SeverityInfo));
this->connect(CLogHandler::instance(), &CLogHandler::remoteMessageLogged, this, &MainWindow::ps_displayStatusMessageInGui); this->connect(logHandler, &CLogPatternHandler::messageLogged, this, &MainWindow::ps_displayStatusMessageInGui);
Q_ASSERT(connect); Q_ASSERT(connect);
Q_UNUSED(connect); // suppress GCC warning in release build Q_UNUSED(connect); // suppress GCC warning in release build