From 297e97da198557a4720960633c9ff8eb91aa527e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 11 Sep 2017 11:03:25 +0200 Subject: [PATCH] Clang: tidy up warnings in logger --- src/libcalamares/CppJob.cpp | 4 +++- src/libcalamares/utils/Logger.cpp | 32 ++++++++++++++++--------------- src/libcalamares/utils/Logger.h | 2 +- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/libcalamares/CppJob.cpp b/src/libcalamares/CppJob.cpp index 1925e398b..73868799a 100644 --- a/src/libcalamares/CppJob.cpp +++ b/src/libcalamares/CppJob.cpp @@ -40,6 +40,8 @@ CppJob::setModuleInstanceKey( const QString& instanceKey ) void CppJob::setConfigurationMap( const QVariantMap& configurationMap ) -{} +{ + Q_UNUSED( configurationMap ); +} } diff --git a/src/libcalamares/utils/Logger.cpp b/src/libcalamares/utils/Logger.cpp index 5c18c2d29..7caf2a18c 100644 --- a/src/libcalamares/utils/Logger.cpp +++ b/src/libcalamares/utils/Logger.cpp @@ -39,9 +39,9 @@ using namespace std; -ofstream logfile; -static int s_threshold = -1; -QMutex s_mutex; +static ofstream logfile; +static unsigned int s_threshold = 0; +static QMutex s_mutex; namespace Logger { @@ -49,20 +49,22 @@ namespace Logger static void log( const char* msg, unsigned int debugLevel, bool toDisk = true ) { - if ( s_threshold < 0 ) + if ( !s_threshold ) { if ( qApp->arguments().contains( "--debug" ) || qApp->arguments().contains( "-d" ) ) s_threshold = LOGVERBOSE; else - #ifdef QT_NO_DEBUG +#ifdef QT_NO_DEBUG s_threshold = RELEASE_LEVEL_THRESHOLD; - #else +#else s_threshold = DEBUG_LEVEL_THRESHOLD; - #endif +#endif + // Comparison is < threshold, below + ++s_threshold; } - if ( toDisk || (int)debugLevel <= s_threshold ) + if ( toDisk || debugLevel < s_threshold ) { QMutexLocker lock( &s_mutex ); @@ -78,7 +80,7 @@ log( const char* msg, unsigned int debugLevel, bool toDisk = true ) logfile.flush(); } - if ( debugLevel <= LOGEXTRA || (int)debugLevel <= s_threshold ) + if ( debugLevel <= LOGEXTRA || debugLevel < s_threshold ) { QMutexLocker lock( &s_mutex ); @@ -96,6 +98,8 @@ CalamaresLogHandler( QtMsgType type, const QMessageLogContext& context, const QS { static QMutex s_mutex; + Q_UNUSED( context ); + QByteArray ba = msg.toUtf8(); const char* message = ba.constData(); @@ -106,14 +110,12 @@ CalamaresLogHandler( QtMsgType type, const QMessageLogContext& context, const QS log( message, LOGVERBOSE ); break; + case QtInfoMsg: + log( message, 1 ); + break; + case QtCriticalMsg: - log( message, 0 ); - break; - case QtWarningMsg: - log( message, 0 ); - break; - case QtFatalMsg: log( message, 0 ); break; diff --git a/src/libcalamares/utils/Logger.h b/src/libcalamares/utils/Logger.h index 72bed2000..0cf4b4ad3 100644 --- a/src/libcalamares/utils/Logger.h +++ b/src/libcalamares/utils/Logger.h @@ -52,7 +52,7 @@ namespace Logger virtual ~CDebug(); }; - DLLEXPORT void CalamaresLogHandler( QtMsgType type, const char* msg ); + DLLEXPORT void CalamaresLogHandler( QtMsgType type, const QMessageLogContext& context, const QString& msg ); DLLEXPORT void setupLogfile(); DLLEXPORT QString logFile(); }