mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-13 15:45:42 +08:00
refs #338 Using CLogPattern for subscribing to log messages in core
This commit is contained in:
committed by
Roland Winklmeier
parent
853caacddf
commit
a07ecfb49b
@@ -33,7 +33,7 @@ int main(int argc, char *argv[])
|
|||||||
// metadata are registered in runtime
|
// metadata are registered in runtime
|
||||||
QApplication a(argc, argv); // not QCoreApplication because of icon, http://qt-project.org/forums/viewthread/15412
|
QApplication a(argc, argv); // not QCoreApplication because of icon, http://qt-project.org/forums/viewthread/15412
|
||||||
CLogHandler::instance()->install();
|
CLogHandler::instance()->install();
|
||||||
CLogHandler::instance()->enableConsoleOutput(false); //! \todo How can I change the level only and display info and above?
|
CLogHandler::instance()->enableConsoleOutput(false); // default disable
|
||||||
QIcon icon(BlackMisc::CIcons::swiftNova24());
|
QIcon icon(BlackMisc::CIcons::swiftNova24());
|
||||||
QApplication::setWindowIcon(icon);
|
QApplication::setWindowIcon(icon);
|
||||||
QTextStream cin(stdin);
|
QTextStream cin(stdin);
|
||||||
|
|||||||
@@ -43,6 +43,12 @@ namespace BlackMiscTest
|
|||||||
Q_ASSERT(runtime);
|
Q_ASSERT(runtime);
|
||||||
QThread::sleep(3); // let the DBus server startup
|
QThread::sleep(3); // let the DBus server startup
|
||||||
|
|
||||||
|
// log
|
||||||
|
//! \todo make thread safe or ..?
|
||||||
|
// CLogSubscriber messageSubscriber;
|
||||||
|
// messageSubscriber.enableConsoleOutput(true);
|
||||||
|
// messageSubscriber.changeSubscription(CLogPattern().withSeverityAtOrAbove(CStatusMessage::SeverityInfo));
|
||||||
|
|
||||||
QTextStream qtout(stdout);
|
QTextStream qtout(stdout);
|
||||||
qtout << "Running on server here " << Tool::getPid() << " thread: " << QThread::currentThreadId() << endl;
|
qtout << "Running on server here " << Tool::getPid() << " thread: " << QThread::currentThreadId() << endl;
|
||||||
|
|
||||||
@@ -53,26 +59,13 @@ namespace BlackMiscTest
|
|||||||
QString line;
|
QString line;
|
||||||
while (line != "x" && runtime)
|
while (line != "x" && runtime)
|
||||||
{
|
{
|
||||||
BlackCore::IContextApplication *applicationContext = runtime->getIContextApplication();
|
|
||||||
BlackCore::IContextNetwork *networkContext = runtime->getIContextNetwork();
|
|
||||||
BlackCore::IContextAudio *audioContext = runtime->getIContextAudio();
|
|
||||||
BlackCore::IContextSettings *settingsContext = runtime->getIContextSettings();
|
|
||||||
BlackCore::IContextOwnAircraft *ownAircraftContext = runtime->getIContextOwnAircraft();
|
|
||||||
BlackCore::IContextSimulator *simulatorContext = runtime->getIContextSimulator();
|
|
||||||
|
|
||||||
qtout << "-------------" << endl;
|
qtout << "-------------" << endl;
|
||||||
qtout << "Connected with network: " << networkContext->isConnected() << endl;
|
qtout << "Connected with network: " << (runtime->getIContextNetwork()->isConnected() ? "yes" : "no") << endl;
|
||||||
qtout << "Thread id: " << QThread::currentThreadId() << endl;
|
qtout << "Thread id: " << QThread::currentThreadId() << endl;
|
||||||
qtout << "-------------" << endl;
|
qtout << "-------------" << endl;
|
||||||
qtout << "x .. to exit 0 .. settings" << endl;
|
qtout << "x .. to exit" << endl;
|
||||||
qtout << "1 .. ATC booked 2 .. ATC online" << endl;
|
qtout << "0 .. settings 1 .. vatlib audio devices 2 .. Qt audio devices" << endl;
|
||||||
qtout << "3 .. Aircrafts in range 4 .. my aircraft 5 .. voice rooms" << endl;
|
qtout << "h .. further commands" << 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;
|
qtout << "-------------" << endl;
|
||||||
|
|
||||||
line = qtin.readLine().toLower().trimmed();
|
line = qtin.readLine().toLower().trimmed();
|
||||||
@@ -80,85 +73,40 @@ namespace BlackMiscTest
|
|||||||
{
|
{
|
||||||
qtout << "-------------" << endl;
|
qtout << "-------------" << endl;
|
||||||
QString ret1;
|
QString ret1;
|
||||||
QMetaObject::invokeMethod(settingsContext, "getSettingsFileName",
|
QMetaObject::invokeMethod(runtime->getIContextSettings(), "getSettingsFileName",
|
||||||
Qt::BlockingQueuedConnection,
|
Qt::BlockingQueuedConnection,
|
||||||
Q_RETURN_ARG(QString, ret1));
|
Q_RETURN_ARG(QString, ret1));
|
||||||
qtout << "Settings: " << ret1 << endl;
|
qtout << "Settings: " << ret1 << endl;
|
||||||
|
|
||||||
|
|
||||||
QMetaObject::invokeMethod(settingsContext, "getSettingsAsJsonString",
|
QMetaObject::invokeMethod(runtime->getIContextSettings(), "getSettingsAsJsonString",
|
||||||
Qt::BlockingQueuedConnection,
|
Qt::BlockingQueuedConnection,
|
||||||
Q_RETURN_ARG(QString, ret1));
|
Q_RETURN_ARG(QString, ret1));
|
||||||
qtout << "JSON " << ret1 << endl;
|
qtout << "JSON " << ret1 << endl;
|
||||||
}
|
}
|
||||||
else if (line.startsWith("1"))
|
else if (line.startsWith("1"))
|
||||||
{
|
|
||||||
// remarks: use fully qualified name in Q_RETURN_ARG
|
|
||||||
qtout << "-------------" << endl;
|
|
||||||
qtout << "ATC booked" << endl;
|
|
||||||
CAtcStationList stations;
|
|
||||||
QMetaObject::invokeMethod(networkContext, "getAtcStationsBooked",
|
|
||||||
Qt::BlockingQueuedConnection,
|
|
||||||
Q_RETURN_ARG(BlackMisc::Aviation::CAtcStationList, stations));
|
|
||||||
qtout << stations << endl;
|
|
||||||
}
|
|
||||||
else if (line.startsWith("2"))
|
|
||||||
{
|
|
||||||
qtout << "-------------" << endl;
|
|
||||||
qtout << "ATC online" << endl;
|
|
||||||
CAtcStationList stations;
|
|
||||||
QMetaObject::invokeMethod(networkContext, "getAtcStationsOnline",
|
|
||||||
Qt::BlockingQueuedConnection,
|
|
||||||
Q_RETURN_ARG(BlackMisc::Aviation::CAtcStationList, stations));
|
|
||||||
qtout << stations << endl;
|
|
||||||
}
|
|
||||||
else if (line.startsWith("3"))
|
|
||||||
{
|
|
||||||
qtout << "-------------" << endl;
|
|
||||||
qtout << "aircrafts in range" << endl;
|
|
||||||
CAircraftList aircrafts;
|
|
||||||
QMetaObject::invokeMethod(networkContext, "getAircraftsInRange",
|
|
||||||
Qt::BlockingQueuedConnection,
|
|
||||||
Q_RETURN_ARG(BlackMisc::Aviation::CAircraftList, aircrafts));
|
|
||||||
qtout << aircrafts << endl;
|
|
||||||
}
|
|
||||||
else if (line.startsWith("4"))
|
|
||||||
{
|
|
||||||
qtout << "-------------" << endl;
|
|
||||||
qtout << "my aircraft" << endl;
|
|
||||||
CAircraft aircraft;
|
|
||||||
QMetaObject::invokeMethod(ownAircraftContext, "getOwnAircraft",
|
|
||||||
Qt::BlockingQueuedConnection,
|
|
||||||
Q_RETURN_ARG(BlackMisc::Aviation::CAircraft, aircraft));
|
|
||||||
qtout << aircraft << endl;
|
|
||||||
|
|
||||||
}
|
|
||||||
else if (line.startsWith("5"))
|
|
||||||
{
|
|
||||||
qtout << "-------------" << endl;
|
|
||||||
qtout << "voice rooms" << endl;
|
|
||||||
CVoiceRoomList voiceRooms;
|
|
||||||
QMetaObject::invokeMethod(audioContext, "getComVoiceRooms",
|
|
||||||
Qt::BlockingQueuedConnection,
|
|
||||||
Q_RETURN_ARG(BlackMisc::Audio::CVoiceRoomList, voiceRooms));
|
|
||||||
qtout << voiceRooms << endl;
|
|
||||||
}
|
|
||||||
else if (line.startsWith("6"))
|
|
||||||
{
|
{
|
||||||
qtout << "-------------" << endl;
|
qtout << "-------------" << endl;
|
||||||
qtout << "vatlib audio devices" << endl;
|
qtout << "vatlib audio devices" << endl;
|
||||||
CAudioDeviceList devices;
|
CAudioDeviceList devices;
|
||||||
QMetaObject::invokeMethod(audioContext, "getAudioDevices",
|
QMetaObject::invokeMethod(runtime->getIContextAudio(), "getAudioDevices",
|
||||||
Qt::BlockingQueuedConnection,
|
Qt::BlockingQueuedConnection,
|
||||||
Q_RETURN_ARG(BlackMisc::Audio::CAudioDeviceList, devices));
|
Q_RETURN_ARG(BlackMisc::Audio::CAudioDeviceList, devices));
|
||||||
qtout << devices << endl;
|
qtout << devices << endl;
|
||||||
}
|
}
|
||||||
else if (line.startsWith("7"))
|
else if (line.startsWith("2"))
|
||||||
{
|
{
|
||||||
qtout << "-------------" << endl;
|
qtout << "-------------" << endl;
|
||||||
qtout << "Qt audio devices" << endl;
|
qtout << "Qt audio devices" << endl;
|
||||||
BlackSound::CSoundGenerator::printAllQtSoundDevices();
|
BlackSound::CSoundGenerator::printAllQtSoundDevices();
|
||||||
}
|
}
|
||||||
|
else if (line.startsWith("level"))
|
||||||
|
{
|
||||||
|
line = line.replace("level", "").trimmed();
|
||||||
|
CStatusMessage::StatusSeverity severity = CStatusMessage::stringToSeverity(line);
|
||||||
|
// messageSubscriber.changeSubscription(CLogPattern().withSeverityAtOrAbove(severity));
|
||||||
|
qtout << "Changed level to" << CStatusMessage::severityToString(severity);
|
||||||
|
}
|
||||||
else if (line.startsWith("log"))
|
else if (line.startsWith("log"))
|
||||||
{
|
{
|
||||||
line.replace("log", "");
|
line.replace("log", "");
|
||||||
@@ -170,12 +118,12 @@ namespace BlackMiscTest
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
CLogCategoryList categories;
|
CLogCategoryList categories;
|
||||||
if (line.startsWith("app")) categories = applicationContext;
|
if (line.startsWith("app")) { categories = runtime->getIContextApplication(); }
|
||||||
else if (line.startsWith("aud")) categories = audioContext;
|
else if (line.startsWith("aud")) { categories = runtime->getIContextAudio(); }
|
||||||
else if (line.startsWith("net")) categories = networkContext;
|
else if (line.startsWith("net")) { categories = runtime->getIContextNetwork(); }
|
||||||
else if (line.startsWith("own")) categories = ownAircraftContext;
|
else if (line.startsWith("own")) { categories = runtime->getIContextOwnAircraft(); }
|
||||||
else if (line.startsWith("set")) categories = settingsContext;
|
else if (line.startsWith("set")) { categories = runtime->getIContextSettings(); }
|
||||||
else if (line.startsWith("sim")) categories = simulatorContext;
|
else if (line.startsWith("sim")) { categories = runtime->getIContextSimulator(); }
|
||||||
if (! categories.isEmpty())
|
if (! categories.isEmpty())
|
||||||
{
|
{
|
||||||
BlackMisc::singleShot(0, BlackMisc::CLogHandler::instance()->thread(), [ = ]()
|
BlackMisc::singleShot(0, BlackMisc::CLogHandler::instance()->thread(), [ = ]()
|
||||||
@@ -185,6 +133,24 @@ namespace BlackMiscTest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (line.startsWith("h"))
|
||||||
|
{
|
||||||
|
qtout << "1) global logging:" << endl;
|
||||||
|
qtout << " levels: d, i, w, e example: level d for debug level" << endl;
|
||||||
|
qtout << "2) logging for contexts:" << 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 << "3) all . commands can be used, e.g. .com1 127.35" << endl;
|
||||||
|
qtout << endl;
|
||||||
|
}
|
||||||
|
else if (line.startsWith("."))
|
||||||
|
{
|
||||||
|
bool c = runtime->parseCommandLine(line);
|
||||||
|
if (c) { qtout << "Handled command " << line; }
|
||||||
|
else { qtout << "Not handled " << line; }
|
||||||
|
qtout << endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
QCoreApplication::quit();
|
QCoreApplication::quit();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user