Merge branch 'improve-logging'
This commit is contained in:
commit
ddbb9eaebc
@ -54,7 +54,7 @@ public:
|
|||||||
for( auto job : m_jobs )
|
for( auto job : m_jobs )
|
||||||
{
|
{
|
||||||
emitProgress();
|
emitProgress();
|
||||||
cLog() << "Starting job" << job->prettyName();
|
cDebug() << "Starting job" << job->prettyName();
|
||||||
connect( job.data(), &Job::progress, this, &JobThread::emitProgress );
|
connect( job.data(), &Job::progress, this, &JobThread::emitProgress );
|
||||||
JobResult result = job->exec();
|
JobResult result = job->exec();
|
||||||
if ( !result )
|
if ( !result )
|
||||||
|
@ -86,7 +86,7 @@ log( const char* msg, unsigned int debugLevel, bool toDisk = true )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
static void
|
||||||
CalamaresLogHandler( QtMsgType type, const QMessageLogContext& context, const QString& msg )
|
CalamaresLogHandler( QtMsgType type, const QMessageLogContext& context, const QString& msg )
|
||||||
{
|
{
|
||||||
static QMutex s_mutex;
|
static QMutex s_mutex;
|
||||||
@ -116,7 +116,7 @@ CalamaresLogHandler( QtMsgType type, const QMessageLogContext& context, const QS
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString
|
static QString
|
||||||
logFile()
|
logFile()
|
||||||
{
|
{
|
||||||
return CalamaresUtils::appLogDir().filePath( "session.log" );
|
return CalamaresUtils::appLogDir().filePath( "session.log" );
|
||||||
@ -177,4 +177,22 @@ CDebug::~CDebug()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* continuation = "\n ";
|
||||||
|
|
||||||
|
QString toString( const QVariant& v )
|
||||||
|
{
|
||||||
|
auto t = v.type();
|
||||||
|
|
||||||
|
if ( t == QVariant::List )
|
||||||
|
{
|
||||||
|
QStringList s;
|
||||||
|
auto l = v.toList();
|
||||||
|
for ( auto lit = l.constBegin(); lit != l.constEnd(); ++lit )
|
||||||
|
s << lit->toString();
|
||||||
|
return s.join(", ");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return v.toString();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -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
|
||||||
@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
namespace Logger
|
namespace Logger
|
||||||
{
|
{
|
||||||
|
extern const char* continuation;
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
LOG_DISABLE = 0,
|
LOG_DISABLE = 0,
|
||||||
@ -41,7 +43,7 @@ namespace Logger
|
|||||||
class DLLEXPORT CLog : public QDebug
|
class DLLEXPORT CLog : public QDebug
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CLog( unsigned int debugLevel = 0 );
|
explicit CLog( unsigned int debugLevel );
|
||||||
virtual ~CLog();
|
virtual ~CLog();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -58,9 +60,14 @@ namespace Logger
|
|||||||
virtual ~CDebug();
|
virtual ~CDebug();
|
||||||
};
|
};
|
||||||
|
|
||||||
DLLEXPORT void CalamaresLogHandler( QtMsgType type, const QMessageLogContext& context, const QString& msg );
|
/**
|
||||||
|
* @brief Start logging to the log file.
|
||||||
|
*
|
||||||
|
* Call this (once) to start logging to the log file (usually
|
||||||
|
* ~/.cache/calamares/session.log ). An existing log file is
|
||||||
|
* rolled over if it is too large.
|
||||||
|
*/
|
||||||
DLLEXPORT void setupLogfile();
|
DLLEXPORT void setupLogfile();
|
||||||
DLLEXPORT QString logFile();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set a log level for future logging.
|
* @brief Set a log level for future logging.
|
||||||
@ -72,9 +79,99 @@ namespace Logger
|
|||||||
* Practical values are 0, 1, 2, and 6.
|
* Practical values are 0, 1, 2, and 6.
|
||||||
*/
|
*/
|
||||||
DLLEXPORT void setupLogLevel( unsigned int level );
|
DLLEXPORT void setupLogLevel( unsigned int level );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Row-oriented formatted logging.
|
||||||
|
*
|
||||||
|
* Use DebugRow to produce multiple rows of 2-column output
|
||||||
|
* in a debugging statement. For instance,
|
||||||
|
* cDebug() << DebugRow<int,int>(1,12)
|
||||||
|
* << DebugRow<int,int>(2,24)
|
||||||
|
* will produce a single timestamped debug line with continuations.
|
||||||
|
* Each DebugRow produces one line of output, with the two values.
|
||||||
|
*/
|
||||||
|
template<typename T, typename U>
|
||||||
|
struct DebugRow
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit DebugRow(const T& t, const U& u)
|
||||||
|
: first(t)
|
||||||
|
, second(u)
|
||||||
|
{}
|
||||||
|
|
||||||
|
const T& first;
|
||||||
|
const U& second;
|
||||||
|
} ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief List-oriented formatted logging.
|
||||||
|
*
|
||||||
|
* Use DebugList to produce multiple rows of output in a debugging
|
||||||
|
* statement. For instance,
|
||||||
|
* cDebug() << DebugList( QStringList() << "foo" << "bar" )
|
||||||
|
* will produce a single timestamped debug line with continuations.
|
||||||
|
* Each element of the list of strings will be logged on a separate line.
|
||||||
|
*/
|
||||||
|
struct DebugList
|
||||||
|
{
|
||||||
|
explicit DebugList( const QStringList& l )
|
||||||
|
: list(l)
|
||||||
|
{}
|
||||||
|
|
||||||
|
const QStringList& list;
|
||||||
|
} ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Map-oriented formatted logging.
|
||||||
|
*
|
||||||
|
* Use DebugMap to produce multiple rows of output in a debugging
|
||||||
|
* statement from a map. The output is intentionally a bit-yaml-ish.
|
||||||
|
* cDebug() << DebugMap( map )
|
||||||
|
* will produce a single timestamped debug line with continuations.
|
||||||
|
* The continued lines will have a key (from the map) and a value
|
||||||
|
* on each line.
|
||||||
|
*/
|
||||||
|
struct DebugMap
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit DebugMap(const QVariantMap& m)
|
||||||
|
: map( m )
|
||||||
|
{}
|
||||||
|
|
||||||
|
const QVariantMap& map;
|
||||||
|
} ;
|
||||||
|
|
||||||
|
/** @brief output operator for DebugRow */
|
||||||
|
template<typename T, typename U>
|
||||||
|
inline QDebug&
|
||||||
|
operator <<( QDebug& s, const DebugRow<T, U>& t )
|
||||||
|
{
|
||||||
|
s << continuation << t.first << ':' << ' ' << t.second;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @brief output operator for DebugList */
|
||||||
|
inline QDebug&
|
||||||
|
operator <<( QDebug& s, const DebugList& c )
|
||||||
|
{
|
||||||
|
for( const auto& i : c.list )
|
||||||
|
s << continuation << i;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @brief supporting method for outputting a DebugMap */
|
||||||
|
QString toString( const QVariant& v );
|
||||||
|
|
||||||
|
/** @brief output operator for DebugMap */
|
||||||
|
inline QDebug&
|
||||||
|
operator <<( QDebug& s, const DebugMap& t )
|
||||||
|
{
|
||||||
|
for ( auto it = t.map.constBegin(); it != t.map.constEnd(); ++it )
|
||||||
|
s << continuation << it.key().toUtf8().constData() << ':' << ' ' << toString( it.value() ).toUtf8().constData();
|
||||||
|
return s;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define cLog Logger::CLog
|
|
||||||
#define cDebug Logger::CDebug
|
#define cDebug Logger::CDebug
|
||||||
#define cWarning() Logger::CDebug(Logger::LOGWARNING) << "WARNING:"
|
#define cWarning() Logger::CDebug(Logger::LOGWARNING) << "WARNING:"
|
||||||
#define cError() Logger::CDebug(Logger::LOGERROR) << "ERROR:"
|
#define cError() Logger::CDebug(Logger::LOGERROR) << "ERROR:"
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
||||||
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
||||||
|
* Copyright 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
|
||||||
@ -64,7 +65,7 @@ ExecutionViewStep::ExecutionViewStep( QObject* parent )
|
|||||||
innerLayout->addWidget( m_progressBar );
|
innerLayout->addWidget( m_progressBar );
|
||||||
innerLayout->addWidget( m_label );
|
innerLayout->addWidget( m_label );
|
||||||
|
|
||||||
cDebug() << "QML import paths:" << m_slideShow->engine()->importPathList();
|
cDebug() << "QML import paths:" << Logger::DebugList( m_slideShow->engine()->importPathList() );
|
||||||
|
|
||||||
connect( JobQueue::instance(), &JobQueue::progress,
|
connect( JobQueue::instance(), &JobQueue::progress,
|
||||||
this, &ExecutionViewStep::updateFromJobQueue );
|
this, &ExecutionViewStep::updateFromJobQueue );
|
||||||
|
@ -150,9 +150,9 @@ ViewManager::insertViewStep( int before, ViewStep* step )
|
|||||||
void
|
void
|
||||||
ViewManager::onInstallationFailed( const QString& message, const QString& details )
|
ViewManager::onInstallationFailed( const QString& message, const QString& details )
|
||||||
{
|
{
|
||||||
cLog() << "Installation failed:";
|
cError() << "Installation failed:";
|
||||||
cLog() << "- message:" << message;
|
cDebug() << "- message:" << message;
|
||||||
cLog() << "- details:" << details;
|
cDebug() << "- details:" << details;
|
||||||
|
|
||||||
QMessageBox* msgBox = new QMessageBox();
|
QMessageBox* msgBox = new QMessageBox();
|
||||||
msgBox->setIcon( QMessageBox::Critical );
|
msgBox->setIcon( QMessageBox::Critical );
|
||||||
@ -167,7 +167,7 @@ ViewManager::onInstallationFailed( const QString& message, const QString& detail
|
|||||||
msgBox->setInformativeText( text );
|
msgBox->setInformativeText( text );
|
||||||
|
|
||||||
connect( msgBox, &QMessageBox::buttonClicked, qApp, &QApplication::quit );
|
connect( msgBox, &QMessageBox::buttonClicked, qApp, &QApplication::quit );
|
||||||
cLog() << "Calamares will quit when the dialog closes.";
|
cDebug() << "Calamares will quit when the dialog closes.";
|
||||||
msgBox->show();
|
msgBox->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,8 +72,7 @@ Module::fromDescriptor( const QVariantMap& moduleDescriptor,
|
|||||||
if ( typeString.isEmpty() ||
|
if ( typeString.isEmpty() ||
|
||||||
intfString.isEmpty() )
|
intfString.isEmpty() )
|
||||||
{
|
{
|
||||||
cLog() << Q_FUNC_INFO << "bad module descriptor format"
|
cError() << "Bad module descriptor format" << instanceId;
|
||||||
<< instanceId;
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if ( ( typeString == "view" ) || ( typeString == "viewmodule" ) )
|
if ( ( typeString == "view" ) || ( typeString == "viewmodule" ) )
|
||||||
@ -87,11 +86,11 @@ Module::fromDescriptor( const QVariantMap& moduleDescriptor,
|
|||||||
#ifdef WITH_PYTHONQT
|
#ifdef WITH_PYTHONQT
|
||||||
m = new PythonQtViewModule();
|
m = new PythonQtViewModule();
|
||||||
#else
|
#else
|
||||||
cLog() << "PythonQt modules are not supported in this version of Calamares.";
|
cError() << "PythonQt modules are not supported in this version of Calamares.";
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cLog() << "Bad interface" << intfString << "for module type" << typeString;
|
cError() << "Bad interface" << intfString << "for module type" << typeString;
|
||||||
}
|
}
|
||||||
else if ( typeString == "job" )
|
else if ( typeString == "job" )
|
||||||
{
|
{
|
||||||
@ -108,18 +107,18 @@ Module::fromDescriptor( const QVariantMap& moduleDescriptor,
|
|||||||
#ifdef WITH_PYTHON
|
#ifdef WITH_PYTHON
|
||||||
m = new PythonJobModule();
|
m = new PythonJobModule();
|
||||||
#else
|
#else
|
||||||
cLog() << "Python modules are not supported in this version of Calamares.";
|
cError() << "Python modules are not supported in this version of Calamares.";
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cLog() << "Bad interface" << intfString << "for module type" << typeString;
|
cError() << "Bad interface" << intfString << "for module type" << typeString;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cLog() << "Bad module type" << typeString;
|
cError() << "Bad module type" << typeString;
|
||||||
|
|
||||||
if ( !m )
|
if ( !m )
|
||||||
{
|
{
|
||||||
cLog() << "Bad module type (" << typeString
|
cDebug() << "Bad module type (" << typeString
|
||||||
<< ") or interface string (" << intfString
|
<< ") or interface string (" << intfString
|
||||||
<< ") for module " << instanceId;
|
<< ") for module " << instanceId;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -130,8 +129,8 @@ Module::fromDescriptor( const QVariantMap& moduleDescriptor,
|
|||||||
m->m_directory = moduleDir.absolutePath();
|
m->m_directory = moduleDir.absolutePath();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cLog() << Q_FUNC_INFO << "bad module directory"
|
cError() << "Bad module directory" << moduleDirectory
|
||||||
<< instanceId;
|
<< "for" << instanceId;
|
||||||
delete m;
|
delete m;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ PartitionModel::parent( const QModelIndex& child ) const
|
|||||||
return createIndex( row, 0, parentNode );
|
return createIndex( row, 0, parentNode );
|
||||||
++row;
|
++row;
|
||||||
}
|
}
|
||||||
cLog() << "No parent found!";
|
cWarning() << "No parent found!";
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,21 +57,21 @@ Calamares::JobResult SetHostNameJob::exec()
|
|||||||
|
|
||||||
if ( !gs || !gs->contains( "rootMountPoint" ) )
|
if ( !gs || !gs->contains( "rootMountPoint" ) )
|
||||||
{
|
{
|
||||||
cLog() << "No rootMountPoint in global storage";
|
cError() << "No rootMountPoint in global storage";
|
||||||
return Calamares::JobResult::error( tr( "Internal Error" ) );
|
return Calamares::JobResult::error( tr( "Internal Error" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
QString destDir = gs->value( "rootMountPoint" ).toString();
|
QString destDir = gs->value( "rootMountPoint" ).toString();
|
||||||
if ( !QDir( destDir ).exists() )
|
if ( !QDir( destDir ).exists() )
|
||||||
{
|
{
|
||||||
cLog() << "rootMountPoint points to a dir which does not exist";
|
cError() << "rootMountPoint points to a dir which does not exist";
|
||||||
return Calamares::JobResult::error( tr( "Internal Error" ) );
|
return Calamares::JobResult::error( tr( "Internal Error" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
QFile hostfile( destDir + "/etc/hostname" );
|
QFile hostfile( destDir + "/etc/hostname" );
|
||||||
if ( !hostfile.open( QFile::WriteOnly ) )
|
if ( !hostfile.open( QFile::WriteOnly ) )
|
||||||
{
|
{
|
||||||
cLog() << "Can't write to hostname file";
|
cError() << "Can't write to hostname file";
|
||||||
return Calamares::JobResult::error( tr( "Cannot write hostname to target system" ) );
|
return Calamares::JobResult::error( tr( "Cannot write hostname to target system" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ Calamares::JobResult SetHostNameJob::exec()
|
|||||||
QFile hostsfile( destDir + "/etc/hosts" );
|
QFile hostsfile( destDir + "/etc/hosts" );
|
||||||
if ( !hostsfile.open( QFile::WriteOnly ) )
|
if ( !hostsfile.open( QFile::WriteOnly ) )
|
||||||
{
|
{
|
||||||
cLog() << "Can't write to hosts file";
|
cError() << "Can't write to hosts file";
|
||||||
return Calamares::JobResult::error( tr( "Cannot write hostname to target system" ) );
|
return Calamares::JobResult::error( tr( "Cannot write hostname to target system" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
*
|
*
|
||||||
* Copyright 2014-2017, Teo Mrnjavac <teo@kde.org>
|
* Copyright 2014-2017, Teo Mrnjavac <teo@kde.org>
|
||||||
* Copyright 2017, Adriaan de Groot <groot@kde.org>
|
* Copyright 2017-2018, Adriaan de Groot <groot@kde.org>
|
||||||
* Copyright 2017, Gabriel Craciunescu <crazy@frugalware.org>
|
* Copyright 2017, Gabriel Craciunescu <crazy@frugalware.org>
|
||||||
*
|
*
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
@ -100,12 +100,14 @@ RequirementsChecker::RequirementsChecker( QObject* parent )
|
|||||||
if ( m_entriesToCheck.contains( "root" ) )
|
if ( m_entriesToCheck.contains( "root" ) )
|
||||||
isRoot = checkIsRoot();
|
isRoot = checkIsRoot();
|
||||||
|
|
||||||
|
using TR = Logger::DebugRow<const char *, bool>;
|
||||||
|
|
||||||
cDebug() << "RequirementsChecker output:"
|
cDebug() << "RequirementsChecker output:"
|
||||||
<< " enoughStorage:" << enoughStorage
|
<< TR("enoughStorage", enoughStorage)
|
||||||
<< " enoughRam:" << enoughRam
|
<< TR("enoughRam", enoughRam)
|
||||||
<< " hasPower:" << hasPower
|
<< TR("hasPower", hasPower)
|
||||||
<< " hasInternet:" << hasInternet
|
<< TR("hasInternet", hasInternet)
|
||||||
<< " isRoot:" << isRoot;
|
<< TR("isRoot", isRoot);
|
||||||
|
|
||||||
QList< PrepareEntry > checkEntries;
|
QList< PrepareEntry > checkEntries;
|
||||||
foreach ( const QString& entry, m_entriesToCheck )
|
foreach ( const QString& entry, m_entriesToCheck )
|
||||||
@ -305,7 +307,9 @@ RequirementsChecker::setConfigurationMap( const QVariantMap& configurationMap )
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( incompleteConfiguration )
|
if ( incompleteConfiguration )
|
||||||
cWarning() << "RequirementsChecker configuration map:\n" << configurationMap;
|
{
|
||||||
|
cWarning() << "RequirementsChecker configuration map:" << Logger::DebugMap( configurationMap );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user