[libcalamares] Rationalize logging

- Move logging-levels to an enum
 - (re-)Order logging-levels so that the normal debug statement is
   not the most-important (lowest level).
 - Drop using namespace std;
This commit is contained in:
Adriaan de Groot 2018-02-12 08:03:04 -05:00
parent 6693f81375
commit ae5511c2f3
3 changed files with 23 additions and 23 deletions

View File

@ -89,7 +89,7 @@ CalamaresApplication::init()
CalamaresApplication::~CalamaresApplication() CalamaresApplication::~CalamaresApplication()
{ {
cDebug( LOGVERBOSE ) << "Shutting down Calamares..."; cDebug( Logger::LOGVERBOSE ) << "Shutting down Calamares...";
// if ( JobQueue::instance() ) // if ( JobQueue::instance() )
// JobQueue::instance()->stop(); // JobQueue::instance()->stop();
@ -98,7 +98,7 @@ CalamaresApplication::~CalamaresApplication()
// delete JobQueue::instance(); // delete JobQueue::instance();
cDebug( LOGVERBOSE ) << "Finished shutdown."; cDebug( Logger::LOGVERBOSE ) << "Finished shutdown.";
} }

View File

@ -2,7 +2,7 @@
* *
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org> * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2014, Teo Mrnjavac <teo@kde.org> * Copyright 2014, Teo Mrnjavac <teo@kde.org>
* Copyright 2017, Adriaan de Groot <groot@kde.org> * Copyright 2017-2018, Adriaan de Groot <groot@kde.org>
* *
* Calamares is free software: you can redistribute it and/or modify * Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -34,13 +34,8 @@
#define LOGFILE_SIZE 1024 * 256 #define LOGFILE_SIZE 1024 * 256
#define RELEASE_LEVEL_THRESHOLD 0 static std::ofstream logfile;
#define DEBUG_LEVEL_THRESHOLD LOGEXTRA static unsigned int s_threshold = 0; // Set to non-zero on first logging call
using namespace std;
static ofstream logfile;
static unsigned int s_threshold = 0;
static QMutex s_mutex; static QMutex s_mutex;
namespace Logger namespace Logger
@ -56,9 +51,9 @@ log( const char* msg, unsigned int debugLevel, bool toDisk = true )
s_threshold = LOGVERBOSE; s_threshold = LOGVERBOSE;
else else
#ifdef QT_NO_DEBUG #ifdef QT_NO_DEBUG
s_threshold = RELEASE_LEVEL_THRESHOLD; s_threshold = LOG_DISABLE;
#else #else
s_threshold = DEBUG_LEVEL_THRESHOLD; s_threshold = LOGEXTRA;
#endif #endif
// Comparison is < threshold, below // Comparison is < threshold, below
++s_threshold; ++s_threshold;
@ -75,7 +70,7 @@ log( const char* msg, unsigned int debugLevel, bool toDisk = true )
<< " - " << " - "
<< QTime::currentTime().toString().toUtf8().data() << QTime::currentTime().toString().toUtf8().data()
<< " [" << QString::number( debugLevel ).toUtf8().data() << "]: " << " [" << QString::number( debugLevel ).toUtf8().data() << "]: "
<< msg << endl; << msg << std::endl;
logfile.flush(); logfile.flush();
} }
@ -84,11 +79,10 @@ log( const char* msg, unsigned int debugLevel, bool toDisk = true )
{ {
QMutexLocker lock( &s_mutex ); QMutexLocker lock( &s_mutex );
cout << QTime::currentTime().toString().toUtf8().data() std::cout << QTime::currentTime().toString().toUtf8().data()
<< " [" << QString::number( debugLevel ).toUtf8().data() << "]: " << " [" << QString::number( debugLevel ).toUtf8().data() << "]: "
<< msg << endl; << msg << std::endl;
std::cout.flush();
cout.flush();
} }
} }
@ -155,7 +149,7 @@ setupLogfile()
cDebug() << "Using log file:" << logFile(); cDebug() << "Using log file:" << logFile();
logfile.open( logFile().toLocal8Bit(), ios::app ); logfile.open( logFile().toLocal8Bit(), std::ios::app );
qInstallMessageHandler( CalamaresLogHandler ); qInstallMessageHandler( CalamaresLogHandler );
} }

View File

@ -25,13 +25,19 @@
#include "DllMacro.h" #include "DllMacro.h"
#define LOGDEBUG 1
#define LOGINFO 2
#define LOGEXTRA 5
#define LOGVERBOSE 8
namespace Logger namespace Logger
{ {
enum
{
LOG_DISABLE = 0,
LOGERROR = 1,
LOGWARNING = 2,
LOGINFO = 3,
LOGEXTRA = 5,
LOGDEBUG = 6,
LOGVERBOSE = 8
} ;
class DLLEXPORT CLog : public QDebug class DLLEXPORT CLog : public QDebug
{ {
public: public: