[calamares] Refactor debug-logging settings

This commit is contained in:
Adriaan de Groot 2020-02-05 14:23:55 +01:00
parent ea8adc3de7
commit f233cac7a1

View File

@ -35,6 +35,21 @@
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>
static unsigned int
debug_level( QCommandLineParser& parser, QCommandLineOption& levelOption )
{
bool ok = true;
int l = parser.value( levelOption ).toInt( &ok );
if ( !ok || ( l < 0 ) )
{
return Logger::LOGVERBOSE;
}
else
{
return static_cast< unsigned int >( l ); // l >= 0
}
}
static void static void
handle_args( CalamaresApplication& a ) handle_args( CalamaresApplication& a )
{ {
@ -59,25 +74,7 @@ handle_args( CalamaresApplication& a )
parser.process( a ); parser.process( a );
a.setDebug( parser.isSet( debugOption ) ); a.setDebug( parser.isSet( debugOption ) );
if ( parser.isSet( debugOption ) ) Logger::setupLogLevel( a.isDebug() ? Logger::LOGVERBOSE : debug_level( parser, debugLevelOption ) );
{
Logger::setupLogLevel( Logger::LOGVERBOSE );
}
else if ( parser.isSet( debugLevelOption ) )
{
bool ok = true;
int l = parser.value( debugLevelOption ).toInt( &ok );
unsigned int dlevel = 0;
if ( !ok || ( l < 0 ) )
{
dlevel = Logger::LOGVERBOSE;
}
else
{
dlevel = static_cast< unsigned int >( l ); // l >= 0
}
Logger::setupLogLevel( dlevel );
}
if ( parser.isSet( configOption ) ) if ( parser.isSet( configOption ) )
{ {
CalamaresUtils::setAppDataDir( QDir( parser.value( configOption ) ) ); CalamaresUtils::setAppDataDir( QDir( parser.value( configOption ) ) );
@ -115,7 +112,6 @@ main( int argc, char* argv[] )
handle_args( a ); handle_args( a );
KDSingleApplicationGuard guard( KDSingleApplicationGuard::AutoKillOtherInstances ); KDSingleApplicationGuard guard( KDSingleApplicationGuard::AutoKillOtherInstances );
if ( guard.isPrimaryInstance() ) if ( guard.isPrimaryInstance() )
{ {
a.init(); a.init();