[libcalamares] Make setup of log-level explicit
- Replace the implicit setting of a logging level (the first time logging is called) with explicit setupLogLevel().
This commit is contained in:
parent
247a0e3a56
commit
a1cbb161ee
@ -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 );
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user