Skip to content

Commit

Permalink
Modified code that opens log file to use new convenience functions. A…
Browse files Browse the repository at this point in the history
…lso added code to get log level and file name info from settings. Further progress on issue AntiMicro#50.
  • Loading branch information
jsbackus committed Sep 20, 2016
1 parent dd91fba commit baf2fd7
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,17 @@ int main(int argc, char *argv[])
return 0;
}

if (cmdutility.getCurrentLogLevel() != appLogger.getCurrentLogLevel())
// 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() ) {
logFile.setFileName( cmdutility.getCurrentLogFile() );
logFile.open( QIODevice::WriteOnly | QIODevice::Append );
logFileStream.setDevice( &logFile );
appLogger.setCurrentStream( &logFileStream );
appLogger.LogInfo(QObject::tr("Logging started"), true, true);
appLogger.setCurrentLogFile( cmdutility.getCurrentLogFile() );
appLogger.setCurrentErrorStream(NULL);
}

Q_INIT_RESOURCE(resources);
Expand All @@ -212,6 +212,18 @@ int main(int argc, char *argv[])
// Save app config and exit.
QApplication a(argc, argv);
AntiMicroSettings settings(PadderCommon::configFilePath, QSettings::IniFormat);

// Update log info based on config values
if( cmdutility.getCurrentLogLevel() == Logger::LOG_NONE &&
settings.contains("LogLevel")) {
appLogger.setLogLevel( (Logger::LogLevel) settings.value("LogLevel").toInt() );
}
if( cmdutility.getCurrentLogFile().isEmpty() &&
settings.contains("LogFile")) {
appLogger.setCurrentLogFile( settings.value("LogFile").toString() );
appLogger.setCurrentErrorStream(NULL);
}

InputDaemon *joypad_worker = new InputDaemon(joysticks, &settings, false);
MainWindow w(joysticks, &cmdutility, &settings, false);
w.fillButtons();
Expand Down Expand Up @@ -456,6 +468,17 @@ int main(int argc, char *argv[])
QSettings::IniFormat);
settings->importFromCommandLine(cmdutility);

// Update log info based on config values
if( cmdutility.getCurrentLogLevel() == Logger::LOG_NONE &&
settings->contains("LogLevel")) {
appLogger.setLogLevel( (Logger::LogLevel)settings->value("LogLevel").toInt() );
}
if( cmdutility.getCurrentLogFile().isEmpty() &&
settings->contains("LogFile")) {
appLogger.setCurrentLogFile( settings->value("LogFile").toString() );
appLogger.setCurrentErrorStream(NULL);
}

QString targetLang = QLocale::system().name();
if (settings->contains("Language"))
{
Expand Down

0 comments on commit baf2fd7

Please sign in to comment.