refactor: use QString to set log level value

fixes: #8999
This commit is contained in:
sithlord48 2025-10-02 08:25:30 -04:00 committed by Nick Bolton
parent 558833ca05
commit 8db65da345
3 changed files with 18 additions and 12 deletions

View file

@ -264,18 +264,19 @@ void Log::pop_front(bool alwaysAtHead)
} }
} }
bool Log::setFilter(const char *maxPriority) bool Log::setFilter(const QString &maxPriority)
{ {
if (maxPriority != nullptr) { if (maxPriority.isEmpty()) {
for (int i = 0; i < g_numPriority; ++i) {
if (strcmp(maxPriority, g_priority[i]) == 0) {
setFilter(static_cast<LogLevel>(i));
return true;
}
}
return false; return false;
} }
return true;
for (int i = 0; i < g_numPriority; ++i) {
if (maxPriority == QString(g_priority[i])) {
setFilter(static_cast<LogLevel>(i));
return true;
}
}
return false;
} }
void Log::setFilter(LogLevel maxPriority) void Log::setFilter(LogLevel maxPriority)

View file

@ -7,6 +7,8 @@
#pragma once #pragma once
#include <QString>
#include "arch/Arch.h" #include "arch/Arch.h"
#include "arch/IArchMultithread.h" #include "arch/IArchMultithread.h"
@ -83,7 +85,7 @@ public:
true if the priority \c name was recognized; if \c name is nullptr true if the priority \c name was recognized; if \c name is nullptr
then it simply returns true. then it simply returns true.
*/ */
bool setFilter(const char *name); bool setFilter(const QString &name);
//! Set the minimum priority filter (by ordinal). //! Set the minimum priority filter (by ordinal).
void setFilter(LogLevel); void setFilter(LogLevel);

View file

@ -143,8 +143,11 @@ void App::initApp(int argc, const char **argv)
parseArgs(); parseArgs();
// set log filter // set log filter
if (const auto logLevel = qPrintable(Settings::logLevelText()); !CLOG->setFilter(logLevel)) { if (const auto logLevel = Settings::logLevelText(); !CLOG->setFilter(logLevel)) {
LOG_CRIT("%s: unrecognized log level `%s'" BYE, qPrintable(processName()), logLevel, qPrintable(processName())); LOG_CRIT(
"%s: unrecognized log level `%s'" BYE, qPrintable(processName()), qPrintable(logLevel),
qPrintable(processName())
);
m_bye(s_exitArgs); m_bye(s_exitArgs);
} }
loggingFilterWarning(); loggingFilterWarning();