Suppress non-critical log output while running the list command

This commit is contained in:
Cameron Gutman 2022-08-25 22:45:42 -05:00
parent 84a32f8c16
commit 0c828cbb37

View File

@ -63,6 +63,7 @@
static QElapsedTimer s_LoggerTime; static QElapsedTimer s_LoggerTime;
static QTextStream s_LoggerStream(stdout); static QTextStream s_LoggerStream(stdout);
static QMutex s_LoggerLock; static QMutex s_LoggerLock;
static bool s_SuppressVerboseOutput;
#ifdef LOG_TO_FILE #ifdef LOG_TO_FILE
#define MAX_LOG_LINES 10000 #define MAX_LOG_LINES 10000
static int s_LogLinesWritten = 0; static int s_LogLinesWritten = 0;
@ -103,15 +104,27 @@ void sdlLogToDiskHandler(void*, int category, SDL_LogPriority priority, const ch
switch (priority) { switch (priority) {
case SDL_LOG_PRIORITY_VERBOSE: case SDL_LOG_PRIORITY_VERBOSE:
if (s_SuppressVerboseOutput) {
return;
}
priorityTxt = "Verbose"; priorityTxt = "Verbose";
break; break;
case SDL_LOG_PRIORITY_DEBUG: case SDL_LOG_PRIORITY_DEBUG:
if (s_SuppressVerboseOutput) {
return;
}
priorityTxt = "Debug"; priorityTxt = "Debug";
break; break;
case SDL_LOG_PRIORITY_INFO: case SDL_LOG_PRIORITY_INFO:
if (s_SuppressVerboseOutput) {
return;
}
priorityTxt = "Info"; priorityTxt = "Info";
break; break;
case SDL_LOG_PRIORITY_WARN: case SDL_LOG_PRIORITY_WARN:
if (s_SuppressVerboseOutput) {
return;
}
priorityTxt = "Warn"; priorityTxt = "Warn";
break; break;
case SDL_LOG_PRIORITY_ERROR: case SDL_LOG_PRIORITY_ERROR:
@ -137,9 +150,15 @@ void qtLogToDiskHandler(QtMsgType type, const QMessageLogContext&, const QString
switch (type) { switch (type) {
case QtDebugMsg: case QtDebugMsg:
if (s_SuppressVerboseOutput) {
return;
}
typeTxt = "Debug"; typeTxt = "Debug";
break; break;
case QtInfoMsg: case QtInfoMsg:
if (s_SuppressVerboseOutput) {
return;
}
typeTxt = "Info"; typeTxt = "Info";
break; break;
case QtWarningMsg: case QtWarningMsg:
@ -169,6 +188,9 @@ void ffmpegLogToDiskHandler(void* ptr, int level, const char* fmt, va_list vl)
if ((level & 0xFF) > av_log_get_level()) { if ((level & 0xFF) > av_log_get_level()) {
return; return;
} }
else if ((level & 0xFF) > AV_LOG_WARNING && s_SuppressVerboseOutput) {
return;
}
// We need to use the *previous* printPrefix value to determine whether to // We need to use the *previous* printPrefix value to determine whether to
// print the prefix this time. av_log_format_line() will set the printPrefix // print the prefix this time. av_log_format_line() will set the printPrefix
@ -263,7 +285,6 @@ int main(int argc, char *argv[])
QCoreApplication::setApplicationName("Moonlight"); QCoreApplication::setApplicationName("Moonlight");
if (QFile(QDir::currentPath() + "/portable.dat").exists()) { if (QFile(QDir::currentPath() + "/portable.dat").exists()) {
qInfo() << "Running in portable mode from:" << QDir::currentPath();
QSettings::setDefaultFormat(QSettings::IniFormat); QSettings::setDefaultFormat(QSettings::IniFormat);
QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, QDir::currentPath()); QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, QDir::currentPath());
QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, QDir::currentPath()); QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, QDir::currentPath());
@ -281,7 +302,7 @@ int main(int argc, char *argv[])
QDir tempDir(Path::getLogDir()); QDir tempDir(Path::getLogDir());
s_LoggerFile = new QFile(tempDir.filePath(QString("Moonlight-%1.log").arg(QDateTime::currentSecsSinceEpoch()))); s_LoggerFile = new QFile(tempDir.filePath(QString("Moonlight-%1.log").arg(QDateTime::currentSecsSinceEpoch())));
if (s_LoggerFile->open(QIODevice::WriteOnly)) { if (s_LoggerFile->open(QIODevice::WriteOnly)) {
qInfo() << "Redirecting log output to " << s_LoggerFile->fileName(); QTextStream(stderr) << "Redirecting log output to " << s_LoggerFile->fileName() << Qt::endl;
s_LoggerStream.setDevice(s_LoggerFile); s_LoggerStream.setDevice(s_LoggerFile);
} }
#endif #endif
@ -630,6 +651,12 @@ int main(int argc, char *argv[])
auto launcher = new CliListApps::Launcher(listParser.getHost(), listParser, &app); auto launcher = new CliListApps::Launcher(listParser.getHost(), listParser, &app);
launcher->execute(new ComputerManager(&app)); launcher->execute(new ComputerManager(&app));
hasGUI = false; hasGUI = false;
#ifdef USE_CUSTOM_LOGGER
// Don't log to the console since it will jumble the command output
s_SuppressVerboseOutput = true;
#endif
break; break;
} }
} }