diff --git a/src/libcalamares/utils/Logger.cpp b/src/libcalamares/utils/Logger.cpp index 24c853bea..fe95ad36b 100644 --- a/src/libcalamares/utils/Logger.cpp +++ b/src/libcalamares/utils/Logger.cpp @@ -35,31 +35,28 @@ #define LOGFILE_SIZE 1024 * 256 static std::ofstream logfile; -static unsigned int s_threshold = 0; // Set to non-zero on first logging call +static unsigned int s_threshold = +#ifdef QT_NO_DEBUG + Logger::LOG_DISABLE; +#else + Logger::LOGEXTRA + 1; // Comparison is < in log() function +#endif static QMutex s_mutex; namespace Logger { +void +setupLogLevel(unsigned int level) +{ + if ( level > LOGVERBOSE ) + level = LOGVERBOSE; + s_threshold = level + 1; // Comparison is < in log() function +} + static void log( const char* msg, unsigned int debugLevel, bool toDisk = true ) { - if ( !s_threshold ) - { - if ( qApp->arguments().contains( "--debug" ) || - qApp->arguments().contains( "-d" ) || - qApp->arguments().contains( "-D" ) ) - s_threshold = LOGVERBOSE; - else -#ifdef QT_NO_DEBUG - s_threshold = LOG_DISABLE; -#else - s_threshold = LOGEXTRA; -#endif - // Comparison is < threshold, below - ++s_threshold; - } - if ( toDisk || debugLevel < s_threshold ) { QMutexLocker lock( &s_mutex ); diff --git a/src/libcalamares/utils/Logger.h b/src/libcalamares/utils/Logger.h index b6c0b4fa7..b6211c4fe 100644 --- a/src/libcalamares/utils/Logger.h +++ b/src/libcalamares/utils/Logger.h @@ -61,6 +61,17 @@ namespace Logger DLLEXPORT void CalamaresLogHandler( QtMsgType type, const QMessageLogContext& context, const QString& msg ); DLLEXPORT void setupLogfile(); DLLEXPORT QString logFile(); + + /** + * @brief Set a log level for future logging. + * + * Pass in a value from the LOG* enum, above. Use 0 to + * disable logging. Values greater than LOGVERBOSE are + * limited to LOGVERBOSE, which will log everything. + * + * Practical values are 0, 1, 2, and 6. + */ + DLLEXPORT void setupLogLevel( unsigned int level ); } #define cLog Logger::CLog