Skip to content

Commit

Permalink
Move applying log settings from commandline mrom main.cpp to CommandL…
Browse files Browse the repository at this point in the history
…ineUtility class
  • Loading branch information
pktiuk committed Aug 4, 2021
1 parent 54f2770 commit b489efc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
16 changes: 16 additions & 0 deletions src/commandlineutility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,22 @@ void CommandLineUtility::parseArguments(const QApplication &parsed_app)
}
}

void CommandLineUtility::applySettingsToLogger(Logger *logger_ptr)
{
if (logger_ptr == nullptr)
logger_ptr = Logger::getInstance();

if (currentLogLevel != Logger::LOG_NONE)
{
logger_ptr->setLogLevel(getCurrentLogLevel());
}

if (!getCurrentLogFile().isEmpty())
{
logger_ptr->setCurrentLogFile(getCurrentLogFile());
}
}

void CommandLineUtility::parseArgsProfile(const QCommandLineParser &parser)
{
QFileInfo profileFileInfo(parser.value("profile"));
Expand Down
7 changes: 7 additions & 0 deletions src/commandlineutility.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ class CommandLineUtility : public QObject
*/
void parseArguments(const QApplication &parsed_app);

/**
* @brief applies settings from command line to logger
*
* @param logger pointer to logger, if nullptr then getInstance() is used
*/
void applySettingsToLogger(Logger *logger = nullptr);

bool isLaunchInTrayEnabled();
bool isTrayHidden();
bool hasProfile();
Expand Down
2 changes: 1 addition & 1 deletion src/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class Logger : public QObject
static Logger *instance;

protected:
explicit Logger(QTextStream *stream, LogLevel outputLevel = LOG_INFO, QObject *parent = nullptr);
explicit Logger(QTextStream *stream, LogLevel outputLevel = LOG_WARNING, QObject *parent = nullptr);
void closeLogger(bool closeStream = true);

QFile outputFile;
Expand Down
15 changes: 1 addition & 14 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,27 +182,14 @@ int main(int argc, char *argv[])
try
{
cmdutility.parseArguments(antimicrox);
cmdutility.applySettingsToLogger(appLogger);
} catch (const std::runtime_error &e)
{
std::cerr << e.what() << '\n';
std::cerr << "Closing\n";
return -1;
}

// If a log level wasn't specified at the command-line, then use a default.
if (cmdutility.getCurrentLogLevel() == Logger::LOG_NONE)
{
appLogger->setLogLevel(Logger::LOG_WARNING);
} else if (cmdutility.getCurrentLogLevel() != appLogger->getCurrentLogLevel())
{
appLogger->setLogLevel(cmdutility.getCurrentLogLevel());
}

if (!cmdutility.getCurrentLogFile().isEmpty())
{
appLogger->setCurrentLogFile(cmdutility.getCurrentLogFile());
}

Q_INIT_RESOURCE(resources);

QDir configDir(PadderCommon::configPath());
Expand Down

0 comments on commit b489efc

Please sign in to comment.