Commit b8e9d480 authored by Don Gagne's avatar Don Gagne

Merge pull request #1911 from DonLakeFlyer/Logging

Easier command line logging options
parents 60099c12 3370a37e
...@@ -51,7 +51,9 @@ void ParseCmdLineOptions(int& argc, ///< count of ar ...@@ -51,7 +51,9 @@ void ParseCmdLineOptions(int& argc, ///< count of ar
if (arg.startsWith(QString("%1:").arg(optionStr), Qt::CaseInsensitive)) { if (arg.startsWith(QString("%1:").arg(optionStr), Qt::CaseInsensitive)) {
found = true; found = true;
prgOpts[iOption].optionArg = arg.right(arg.length() - (optionStr.length() + 1)); if (prgOpts[iOption].optionArg) {
*prgOpts[iOption].optionArg = arg.right(arg.length() - (optionStr.length() + 1));
}
} else if (arg.compare(optionStr, Qt::CaseInsensitive) == 0) { } else if (arg.compare(optionStr, Qt::CaseInsensitive) == 0) {
found = true; found = true;
} }
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
typedef struct { typedef struct {
const char* optionStr; ///< command line option, for example "--foo" const char* optionStr; ///< command line option, for example "--foo"
bool* optionFound; ///< if option is found this variable will be set to true bool* optionFound; ///< if option is found this variable will be set to true
QString optionArg; ///< Option has additional argument, form is option:arg QString* optionArg; ///< Option has additional argument, form is option:arg
} CmdLineOpt_t; } CmdLineOpt_t;
void ParseCmdLineOptions(int& argc, void ParseCmdLineOptions(int& argc,
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include <QDebug> #include <QDebug>
QGC_LOGGING_CATEGORY(ParameterLoaderLog, "ParameterLoaderLog") QGC_LOGGING_CATEGORY(ParameterLoaderLog, "ParameterLoaderLog")
QGC_LOGGING_CATEGORY(ParameterLoaderVerboseLog, "ParameterLoaderVerboseLog")
Fact ParameterLoader::_defaultFact; Fact ParameterLoader::_defaultFact;
...@@ -130,7 +131,7 @@ void ParameterLoader::_parameterUpdate(int uasId, int componentId, QString param ...@@ -130,7 +131,7 @@ void ParameterLoader::_parameterUpdate(int uasId, int componentId, QString param
_waitingReadParamIndexMap[componentId].remove(parameterId); _waitingReadParamIndexMap[componentId].remove(parameterId);
_waitingReadParamNameMap[componentId].remove(parameterName); _waitingReadParamNameMap[componentId].remove(parameterName);
_waitingWriteParamNameMap[componentId].remove(parameterName); _waitingWriteParamNameMap[componentId].remove(parameterName);
qCDebug(ParameterLoaderLog) << "_waitingReadParamIndexMap:" << _waitingReadParamIndexMap[componentId]; qCDebug(ParameterLoaderVerboseLog) << "_waitingReadParamIndexMap:" << _waitingReadParamIndexMap[componentId];
qCDebug(ParameterLoaderLog) << "_waitingReadParamNameMap" << _waitingReadParamNameMap[componentId]; qCDebug(ParameterLoaderLog) << "_waitingReadParamNameMap" << _waitingReadParamNameMap[componentId];
qCDebug(ParameterLoaderLog) << "_waitingWriteParamNameMap" << _waitingWriteParamNameMap[componentId]; qCDebug(ParameterLoaderLog) << "_waitingWriteParamNameMap" << _waitingWriteParamNameMap[componentId];
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
/// @author Don Gagne <don@thegagnes.com> /// @author Don Gagne <don@thegagnes.com>
Q_DECLARE_LOGGING_CATEGORY(ParameterLoaderLog) Q_DECLARE_LOGGING_CATEGORY(ParameterLoaderLog)
Q_DECLARE_LOGGING_CATEGORY(ParameterLoaderVerboseLog)
/// Connects to Parameter Manager to load/update Facts /// Connects to Parameter Manager to load/update Facts
class ParameterLoader : public QObject class ParameterLoader : public QObject
......
...@@ -180,14 +180,15 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting) ...@@ -180,14 +180,15 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting)
// Parse command line options // Parse command line options
bool fClearSettingsOptions = false; // Clear stored settings bool fClearSettingsOptions = false; // Clear stored settings
bool fullLogging = false; // Turn on all logging bool logging = false; // Turn on logging
QString loggingOptions;
CmdLineOpt_t rgCmdLineOptions[] = { CmdLineOpt_t rgCmdLineOptions[] = {
{ "--clear-settings", &fClearSettingsOptions, QString() }, { "--clear-settings", &fClearSettingsOptions, NULL },
{ "--full-logging", &fullLogging, QString() }, { "--logging", &logging, &loggingOptions },
{ "--fake-mobile", &_fakeMobile, QString() }, { "--fake-mobile", &_fakeMobile, NULL },
#ifdef QT_DEBUG #ifdef QT_DEBUG
{ "--test-high-dpi", &_testHighDPI, QString() }, { "--test-high-dpi", &_testHighDPI, NULL },
#endif #endif
// Add additional command line option flags here // Add additional command line option flags here
}; };
...@@ -197,8 +198,30 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting) ...@@ -197,8 +198,30 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting)
#ifdef __mobile__ #ifdef __mobile__
QLoggingCategory::setFilterRules(QStringLiteral("*Log.debug=false")); QLoggingCategory::setFilterRules(QStringLiteral("*Log.debug=false"));
#else #else
if (fullLogging) { if (logging) {
QLoggingCategory::setFilterRules(QStringLiteral("*Log=true")); QString filterRules;
QStringList logList = loggingOptions.split(",");
if (logList[0] == "full") {
filterRules += "*Log.debug=true\n";
for(int i=1; i<logList.count(); i++) {
filterRules += logList[i];
filterRules += ".debug=false\n";
}
} else {
foreach(QString rule, logList) {
filterRules += rule;
filterRules += ".debug=true\n";
}
}
if (_runningUnitTests) {
// We need to turn off these warnings until the firmware meta data is cleaned up
filterRules += "PX4ParameterLoaderLog.warning=false\n";
}
qDebug() << "Filter rules" << filterRules;
QLoggingCategory::setFilterRules(filterRules);
} else { } else {
if (_runningUnitTests) { if (_runningUnitTests) {
// We need to turn off these warnings until the firmware meta data is cleaned up // We need to turn off these warnings until the firmware meta data is cleaned up
...@@ -227,7 +250,7 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting) ...@@ -227,7 +250,7 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting)
} }
if (loggingDirectoryOk) { if (loggingDirectoryOk) {
qDebug () << iniFileLocation; qDebug () << "Logging ini file directory" << iniFileLocation.absolutePath();
if (!iniFileLocation.exists(qtLoggingFile)) { if (!iniFileLocation.exists(qtLoggingFile)) {
QFile loggingFile(iniFileLocation.filePath(qtLoggingFile)); QFile loggingFile(iniFileLocation.filePath(qtLoggingFile));
if (loggingFile.open(QIODevice::WriteOnly | QIODevice::Text)) { if (loggingFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
......
...@@ -135,9 +135,10 @@ int main(int argc, char *argv[]) ...@@ -135,9 +135,10 @@ int main(int argc, char *argv[])
bool quietWindowsAsserts = false; // Don't let asserts pop dialog boxes bool quietWindowsAsserts = false; // Don't let asserts pop dialog boxes
QString unitTestOptions;
CmdLineOpt_t rgCmdLineOptions[] = { CmdLineOpt_t rgCmdLineOptions[] = {
{ "--unittest", &runUnitTests, QString() }, { "--unittest", &runUnitTests, &unitTestOptions },
{ "--no-windows-assert-ui", &quietWindowsAsserts, QString() }, { "--no-windows-assert-ui", &quietWindowsAsserts, NULL },
// Add additional command line option flags here // Add additional command line option flags here
}; };
...@@ -181,7 +182,7 @@ int main(int argc, char *argv[]) ...@@ -181,7 +182,7 @@ int main(int argc, char *argv[])
} }
// Run the test // Run the test
int failures = UnitTest::run(rgCmdLineOptions[0].optionArg); int failures = UnitTest::run(unitTestOptions);
if (failures == 0) { if (failures == 0) {
qDebug() << "ALL TESTS PASSED"; qDebug() << "ALL TESTS PASSED";
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment