refactor: move Log option to coreArgs
This commit is contained in:
committed by
Chris Rizzitello
parent
f3a1bbaf5b
commit
53b36801e1
@ -123,19 +123,22 @@ int App::daemonMainLoop(int, const char **)
|
||||
|
||||
void App::setupFileLogging()
|
||||
{
|
||||
if (argsBase().m_logFile != nullptr) {
|
||||
m_fileLog = new FileLogOutputter(argsBase().m_logFile); // NOSONAR - Adopted by `Log`
|
||||
CLOG->insert(m_fileLog);
|
||||
LOG_DEBUG1("logging to file (%s) enabled", argsBase().m_logFile);
|
||||
if (Settings::value(Settings::Log::ToFile).toBool()) {
|
||||
if (const auto file = Settings::value(Settings::Log::File).toString(); !file.isEmpty()) {
|
||||
const auto logFile = qPrintable(file);
|
||||
m_fileLog = new FileLogOutputter(logFile); // NOSONAR - Adopted by `Log`
|
||||
CLOG->insert(m_fileLog);
|
||||
LOG_DEBUG1("logging to file (%s) enabled", logFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void App::loggingFilterWarning() const
|
||||
{
|
||||
if ((CLOG->getFilter() > CLOG->getConsoleMaxLevel()) && (argsBase().m_logFile == nullptr)) {
|
||||
LOG(
|
||||
(CLOG_WARN "log messages above %s are NOT sent to console (use file logging)",
|
||||
CLOG->getFilterName(CLOG->getConsoleMaxLevel()))
|
||||
if ((CLOG->getFilter() > CLOG->getConsoleMaxLevel()) && (Settings::value(Settings::Log::ToFile).toBool())) {
|
||||
LOG_WARN(
|
||||
"log messages above %s are NOT sent to console (use file logging)",
|
||||
CLOG->getFilterName(CLOG->getConsoleMaxLevel())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,7 +131,6 @@ private:
|
||||
constexpr static auto s_helpGeneralArgs = //
|
||||
" -1, --no-restart do not try to restart on failure.\n"
|
||||
"* --restart restart the server automatically if it fails.\n"
|
||||
" -l --log <file> write log messages to file.\n"
|
||||
" --enable-crypto enable TLS encryption.\n"
|
||||
" --tls-cert specify the path to the TLS certificate file.\n";
|
||||
|
||||
|
||||
@ -122,9 +122,7 @@ bool ArgParser::parsePlatformArgs(deskflow::ArgsBase &argsBase, const int &argc,
|
||||
|
||||
bool ArgParser::parseGenericArgs(int argc, const char *const *argv, int &i) const
|
||||
{
|
||||
if (isArg(i, argc, argv, "-l", "--log", 1)) {
|
||||
argsBase().m_logFile = argv[++i];
|
||||
} else if (isArg(i, argc, argv, "-1", "--no-restart")) {
|
||||
if (isArg(i, argc, argv, "-1", "--no-restart")) {
|
||||
// don't try to restart
|
||||
argsBase().m_restartable = false;
|
||||
} else if (isArg(i, argc, argv, nullptr, "--restart")) {
|
||||
@ -157,9 +155,8 @@ bool ArgParser::parseGenericArgs(int argc, const char *const *argv, int &i) cons
|
||||
|
||||
bool ArgParser::parseDeprecatedArgs(int argc, const char *const *argv, int &i) const
|
||||
{
|
||||
static const std::vector<const char *> deprecatedArgs = {
|
||||
"--crypto-pass", "--res-w", "--res-h", "--prm-wc", "--prm-hc"
|
||||
};
|
||||
static const std::vector<const char *> deprecatedArgs = {"--crypto-pass", "--res-w", "--res-h",
|
||||
"--prm-wc", "--prm-hc", "--log"};
|
||||
|
||||
for (auto &arg : deprecatedArgs) {
|
||||
if (isArg(i, argc, argv, nullptr, arg)) {
|
||||
|
||||
@ -41,9 +41,6 @@ public:
|
||||
/// @brief The filename of the running process
|
||||
const char *m_pname = nullptr;
|
||||
|
||||
/// @brief The full path to the logfile
|
||||
const char *m_logFile = nullptr;
|
||||
|
||||
/// @brief Contains the X-Server display to use
|
||||
const char *m_display = nullptr;
|
||||
|
||||
|
||||
@ -65,6 +65,13 @@ void CoreArgParser::parse()
|
||||
if (m_parser.isSet(CoreArgs::logLevelOption)) {
|
||||
Settings::setValue(Settings::Log::Level, Settings::logLevelToInt(m_parser.value(CoreArgs::logLevelOption)));
|
||||
}
|
||||
|
||||
if (m_parser.isSet(CoreArgs::logFileOption)) {
|
||||
Settings::setValue(Settings::Log::File, m_parser.value(CoreArgs::logFileOption));
|
||||
Settings::setValue(Settings::Log::ToFile, true);
|
||||
} else {
|
||||
Settings::setValue(Settings::Log::ToFile, false);
|
||||
}
|
||||
}
|
||||
|
||||
[[noreturn]] void CoreArgParser::showHelpText() const
|
||||
|
||||
@ -36,6 +36,8 @@ struct CoreArgs
|
||||
"level"
|
||||
);
|
||||
|
||||
inline static const auto options = {helpOption, versionOption, configOption, interfaceOption,
|
||||
portOption, nameOption, logLevelOption};
|
||||
inline static const auto logFileOption = QCommandLineOption({"l", "log"}, "Write messages to file", "file");
|
||||
|
||||
inline static const auto options = {helpOption, versionOption, configOption, interfaceOption,
|
||||
portOption, nameOption, logLevelOption, logFileOption};
|
||||
};
|
||||
|
||||
@ -290,30 +290,6 @@ void ArgParserTests::deprecatedArg_crypoPass_false()
|
||||
QCOMPARE(i, 1);
|
||||
}
|
||||
|
||||
void ArgParserTests::generic_logFile()
|
||||
{
|
||||
int i = 1;
|
||||
const int argc = 3;
|
||||
const char *kLogFileCmd[argc] = {"stub", "--log", "mock_filename"};
|
||||
|
||||
m_parser.parseGenericArgs(argc, kLogFileCmd, i);
|
||||
|
||||
QCOMPARE(m_parser.argsBase().m_logFile, "mock_filename");
|
||||
QCOMPARE(i, 2);
|
||||
}
|
||||
|
||||
void ArgParserTests::generic_logFileWithSpace()
|
||||
{
|
||||
int i = 1;
|
||||
const int argc = 3;
|
||||
const char *kLogFileCmdWithSpace[argc] = {"stub", "--log", "mo ck_filename"};
|
||||
|
||||
m_parser.parseGenericArgs(argc, kLogFileCmdWithSpace, i);
|
||||
|
||||
QCOMPARE(m_parser.argsBase().m_logFile, "mo ck_filename");
|
||||
QCOMPARE(i, 2);
|
||||
}
|
||||
|
||||
void ArgParserTests::generic_noRestart()
|
||||
{
|
||||
int i = 1;
|
||||
|
||||
@ -33,8 +33,6 @@ private Q_SLOTS:
|
||||
void client_badArgs();
|
||||
void deprecatedArg_crypoPass_true();
|
||||
void deprecatedArg_crypoPass_false();
|
||||
void generic_logFile();
|
||||
void generic_logFileWithSpace();
|
||||
void generic_noRestart();
|
||||
void generic_restart();
|
||||
void generic_unknown();
|
||||
|
||||
@ -90,4 +90,24 @@ void CoreArgParserTests::logLevel()
|
||||
QCOMPARE(Settings::value(Settings::Log::Level).toInt(), 6);
|
||||
}
|
||||
|
||||
void CoreArgParserTests::logFile()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--log", "mock_filename"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QCOMPARE(Settings::value(Settings::Log::File).toString(), "mock_filename");
|
||||
}
|
||||
|
||||
void CoreArgParserTests::logFileWithSpace()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--log", "mock filename"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QCOMPARE(Settings::value(Settings::Log::File).toString(), "mock filename");
|
||||
}
|
||||
|
||||
QTEST_MAIN(CoreArgParserTests)
|
||||
|
||||
@ -21,6 +21,8 @@ private Q_SLOTS:
|
||||
void nameLong();
|
||||
void nameShort();
|
||||
void logLevel();
|
||||
void logFile();
|
||||
void logFileWithSpace();
|
||||
|
||||
private:
|
||||
inline static const QString m_settingsPath = QStringLiteral("tmp/test");
|
||||
|
||||
Reference in New Issue
Block a user