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) {
for (int i = 0; i < g_numPriority; ++i) {
if (strcmp(maxPriority, g_priority[i]) == 0) {
setFilter(static_cast<LogLevel>(i));
return true;
}
}
if (maxPriority.isEmpty()) {
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)

View File

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

View File

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