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