Improve error reporting for incorrect --logOptions

This commit is contained in:
Dale Glass 2022-06-27 20:37:34 +02:00
parent 545ee0840b
commit 214dce833d
5 changed files with 8 additions and 7 deletions

View file

@ -129,7 +129,7 @@ AssignmentClientApp::AssignmentClientApp(int argc, char* argv[]) :
// We want to configure the logging system as early as possible // We want to configure the logging system as early as possible
auto &logHandler = LogHandler::getInstance(); auto &logHandler = LogHandler::getInstance();
if (parser.isSet(logOption)) { if (parser.isSet(logOption)) {
if (!logHandler.parseOptions(parser.value(logOption).toUtf8())) { if (!logHandler.parseOptions(parser.value(logOption).toUtf8(), logOption.names().first())) {
QCoreApplication mockApp(argc, const_cast<char**>(argv)); // required for call to showHelp() QCoreApplication mockApp(argc, const_cast<char**>(argv)); // required for call to showHelp()
parser.showHelp(); parser.showHelp();
Q_UNREACHABLE(); Q_UNREACHABLE();

View file

@ -442,7 +442,7 @@ void DomainServer::parseCommandLine(int argc, char* argv[]) {
// We want to configure the logging system as early as possible // We want to configure the logging system as early as possible
auto &logHandler = LogHandler::getInstance(); auto &logHandler = LogHandler::getInstance();
if (parser.isSet(logOption)) { if (parser.isSet(logOption)) {
if (!logHandler.parseOptions(parser.value(logOption).toUtf8())) { if (!logHandler.parseOptions(parser.value(logOption).toUtf8(), logOption.names().first())) {
QCoreApplication mockApp(argc, const_cast<char**>(argv)); // required for call to showHelp() QCoreApplication mockApp(argc, const_cast<char**>(argv)); // required for call to showHelp()
parser.showHelp(); parser.showHelp();
Q_UNREACHABLE(); Q_UNREACHABLE();

View file

@ -311,7 +311,7 @@ int main(int argc, const char* argv[]) {
// We want to configure the logging system as early as possible // We want to configure the logging system as early as possible
auto &logHandler = LogHandler::getInstance(); auto &logHandler = LogHandler::getInstance();
if (parser.isSet(logOption)) { if (parser.isSet(logOption)) {
if (!logHandler.parseOptions(parser.value(logOption).toUtf8())) { if (!logHandler.parseOptions(parser.value(logOption).toUtf8(), logOption.names().first())) {
QCoreApplication mockApp(argc, const_cast<char**>(argv)); // required for call to showHelp() QCoreApplication mockApp(argc, const_cast<char**>(argv)); // required for call to showHelp()
parser.showHelp(); parser.showHelp();
Q_UNREACHABLE(); Q_UNREACHABLE();

View file

@ -61,7 +61,7 @@ LogHandler::LogHandler() {
_useJournald = true; _useJournald = true;
#endif #endif
parseOptions(logOptions); parseOptions(logOptions, "VIRCADIA_LOG_OPTIONS");
} }
const char* stringForLogType(LogMsgType msgType) { const char* stringForLogType(LogMsgType msgType) {
@ -121,7 +121,7 @@ const QString DATE_STRING_FORMAT = "MM/dd hh:mm:ss";
// the following will produce 11/18 13:55:36.999 // the following will produce 11/18 13:55:36.999
const QString DATE_STRING_FORMAT_WITH_MILLISECONDS = "MM/dd hh:mm:ss.zzz"; const QString DATE_STRING_FORMAT_WITH_MILLISECONDS = "MM/dd hh:mm:ss.zzz";
bool LogHandler::parseOptions(QString logOptions) { bool LogHandler::parseOptions(const QString& logOptions, const QString& paramName) {
QMutexLocker lock(&_mutex); QMutexLocker lock(&_mutex);
auto optionList = logOptions.split(","); auto optionList = logOptions.split(",");
@ -145,7 +145,7 @@ bool LogHandler::parseOptions(QString logOptions) {
} else if (option == "nojournald") { } else if (option == "nojournald") {
_useJournald = false; _useJournald = false;
} else if (option != "") { } else if (option != "") {
fprintf(stdout, "Unrecognized option in VIRCADIA_LOG_OPTIONS: '%s'\n", option.toUtf8().constData()); fprintf(stderr, "Unrecognized option in %s: '%s'\n", paramName.toUtf8().constData(), option.toUtf8().constData());
return false; return false;
} }
} }

View file

@ -53,10 +53,11 @@ public:
* This parses the logging settings in the environment variable, or from the commandline * This parses the logging settings in the environment variable, or from the commandline
* *
* @param options Option list * @param options Option list
* @param paramName Name of the log option, for error reporting.
* @return true Option list was parsed successfully * @return true Option list was parsed successfully
* @return false There was an error * @return false There was an error
*/ */
bool parseOptions(QString options); bool parseOptions(const QString& options, const QString &paramName);
/** /**
* @brief Set the name of the component that's producing log output * @brief Set the name of the component that's producing log output