Merge branch 'improve-logger'

This commit is contained in:
Adriaan de Groot 2019-04-15 08:29:40 -04:00
commit 81bd173b7e
6 changed files with 29 additions and 81 deletions

View File

@ -44,7 +44,7 @@ requireString( const YAML::Node& config, const char* key )
return QString::fromStdString( v.as< std::string >() ); return QString::fromStdString( v.as< std::string >() );
else else
{ {
cWarning() << Logger::SubEntry() << "Required settings.conf key" << key << "is missing."; cWarning() << Logger::SubEntry << "Required settings.conf key" << key << "is missing.";
return QString(); return QString();
} }
} }
@ -58,7 +58,7 @@ requireBool( const YAML::Node& config, const char* key, bool d )
return v.as< bool >(); return v.as< bool >();
else else
{ {
cWarning() << Logger::SubEntry() << "Required settings.conf key" << key << "is missing."; cWarning() << Logger::SubEntry << "Required settings.conf key" << key << "is missing.";
return d; return d;
} }
} }
@ -106,7 +106,7 @@ interpretModulesSearch( const bool debugMode, const QStringList& rawPaths, QStri
output.append( d.absolutePath() ); output.append( d.absolutePath() );
} }
else else
cDebug() << Logger::SubEntry() << "module-search entry non-existent" << path; cDebug() << Logger::SubEntry << "module-search entry non-existent" << path;
} }
} }
} }

View File

@ -189,36 +189,8 @@ CDebug::~CDebug()
{ {
} }
static const char continuation[] = "\n "; const char Continuation[] = "\n ";
static const char subentry[] = " .. "; const char SubEntry[] = " .. ";
QDebug&
operator<<( QDebug& s, Continuation )
{
s << continuation;
return s;
}
QDebug&
operator<<( QDebug& s, SubEntry )
{
s << subentry;
return s;
}
CDebug&
operator<<( CDebug&& s, Continuation )
{
s << continuation;
return s;
}
CDebug&
operator<<( CDebug&& s, SubEntry )
{
s << subentry;
return s;
}
QString toString( const QVariant& v ) QString toString( const QVariant& v )
{ {

View File

@ -27,25 +27,8 @@
namespace Logger namespace Logger
{ {
/** @brief tag-class used for continuing debug-output on the next line DLLEXPORT extern const char Continuation[];
* DLLEXPORT extern const char SubEntry[];
* A continuation starts a new debug-log line, without the timestamp and
* other leading information. Used when dumping tables and lists. Represented
* in the log by a newline and four spaces.
*/
struct Continuation
{
} ;
/** @brief tag-class used to indicate a log line is a sub-entry
*
* Sub-entries indicate additional information that isn't a continuation
* of the previous line, or sub-steps of something that has already been logged.
* Represented in the log as space dot dot space.
*/
struct SubEntry
{
} ;
enum enum
{ {
@ -113,13 +96,6 @@ namespace Logger
/** @brief Would the given @p level really be logged? */ /** @brief Would the given @p level really be logged? */
DLLEXPORT bool logLevelEnabled( unsigned int level ); DLLEXPORT bool logLevelEnabled( unsigned int level );
/// @brief Output a continuation
DLLEXPORT CDebug& operator <<( CDebug&& s, Continuation c );
DLLEXPORT QDebug& operator <<( QDebug& s, Continuation c );
/// @brief Output a subentry marker
DLLEXPORT CDebug& operator <<( CDebug&& s, SubEntry level );
DLLEXPORT QDebug& operator <<( QDebug& s, SubEntry level );
/** /**
* @brief Row-oriented formatted logging. * @brief Row-oriented formatted logging.
* *
@ -186,7 +162,7 @@ namespace Logger
inline QDebug& inline QDebug&
operator <<( QDebug& s, const DebugRow<T, U>& t ) operator <<( QDebug& s, const DebugRow<T, U>& t )
{ {
s << Continuation() << t.first << ':' << ' ' << t.second; s << Continuation << t.first << ':' << ' ' << t.second;
return s; return s;
} }
@ -195,7 +171,7 @@ namespace Logger
operator <<( QDebug& s, const DebugList& c ) operator <<( QDebug& s, const DebugList& c )
{ {
for( const auto& i : c.list ) for( const auto& i : c.list )
s << Continuation() << i; s << Continuation << i;
return s; return s;
} }
@ -207,7 +183,7 @@ namespace Logger
operator <<( QDebug& s, const DebugMap& t ) operator <<( QDebug& s, const DebugMap& t )
{ {
for ( auto it = t.map.constBegin(); it != t.map.constEnd(); ++it ) for ( auto it = t.map.constBegin(); it != t.map.constEnd(); ++it )
s << Continuation() << it.key().toUtf8().constData() << ':' << ' ' << toString( it.value() ).toUtf8().constData(); s << Continuation << it.key().toUtf8().constData() << ':' << ' ' << toString( it.value() ).toUtf8().constData();
return s; return s;
} }
} }

View File

@ -116,7 +116,7 @@ QList< Device* > getDevices( DeviceType which, qint64 minimumSize )
#ifdef DEBUG_PARTITION_UNSAFE #ifdef DEBUG_PARTITION_UNSAFE
cWarning() << "Allowing unsafe partitioning choices." << devices.count() << "candidates."; cWarning() << "Allowing unsafe partitioning choices." << devices.count() << "candidates.";
#ifdef DEBUG_PARTITION_LAME #ifdef DEBUG_PARTITION_LAME
cDebug() << Logger::SubEntry() << "it has been lamed, and will fail."; cDebug() << Logger::SubEntry << "it has been lamed, and will fail.";
#endif #endif
#else #else
cDebug() << "Removing unsuitable devices:" << devices.count() << "candidates."; cDebug() << "Removing unsuitable devices:" << devices.count() << "candidates.";
@ -125,29 +125,29 @@ QList< Device* > getDevices( DeviceType which, qint64 minimumSize )
for ( DeviceList::iterator it = devices.begin(); it != devices.end(); ) for ( DeviceList::iterator it = devices.begin(); it != devices.end(); )
if ( !( *it ) ) if ( !( *it ) )
{ {
cDebug() << Logger::SubEntry() << "Skipping nullptr device"; cDebug() << Logger::SubEntry << "Skipping nullptr device";
it = erase( devices, it); it = erase( devices, it);
} }
else if ( ( *it )->deviceNode().startsWith( "/dev/zram" ) else if ( ( *it )->deviceNode().startsWith( "/dev/zram" )
) )
{ {
cDebug() << Logger::SubEntry() << "Removing zram" << it; cDebug() << Logger::SubEntry << "Removing zram" << it;
it = erase( devices, it ); it = erase( devices, it );
} }
else if ( writableOnly && hasRootPartition( *it ) ) else if ( writableOnly && hasRootPartition( *it ) )
{ {
cDebug() << Logger::SubEntry() << "Removing device with root filesystem (/) on it" << it; cDebug() << Logger::SubEntry << "Removing device with root filesystem (/) on it" << it;
it = erase( devices, it ); it = erase( devices, it );
} }
else if ( writableOnly && isIso9660( *it ) ) else if ( writableOnly && isIso9660( *it ) )
{ {
cDebug() << Logger::SubEntry() << "Removing device with iso9660 filesystem (probably a CD) on it" << it; cDebug() << Logger::SubEntry << "Removing device with iso9660 filesystem (probably a CD) on it" << it;
it = erase( devices, it ); it = erase( devices, it );
} }
else if ( (minimumSize >= 0) && !( (*it)->capacity() > minimumSize ) ) else if ( (minimumSize >= 0) && !( (*it)->capacity() > minimumSize ) )
{ {
cDebug() << Logger::SubEntry() << "Removing too-small" << it; cDebug() << Logger::SubEntry << "Removing too-small" << it;
it = erase( devices, it ); it = erase( devices, it );
} }
else else

View File

@ -109,20 +109,20 @@ canBeResized( Partition* candidate )
if ( !candidate->fileSystem().supportGrow() || if ( !candidate->fileSystem().supportGrow() ||
!candidate->fileSystem().supportShrink() ) !candidate->fileSystem().supportShrink() )
{ {
cDebug() << Logger::SubEntry() << "NO, filesystem" << candidate->fileSystem().name() cDebug() << Logger::SubEntry << "NO, filesystem" << candidate->fileSystem().name()
<< "does not support resize."; << "does not support resize.";
return false; return false;
} }
if ( KPMHelpers::isPartitionFreeSpace( candidate ) ) if ( KPMHelpers::isPartitionFreeSpace( candidate ) )
{ {
cDebug() << Logger::SubEntry() << "NO, partition is free space"; cDebug() << Logger::SubEntry << "NO, partition is free space";
return false; return false;
} }
if ( candidate->isMounted() ) if ( candidate->isMounted() )
{ {
cDebug() << Logger::SubEntry() << "NO, partition is mounted"; cDebug() << Logger::SubEntry << "NO, partition is mounted";
return false; return false;
} }
@ -131,13 +131,13 @@ canBeResized( Partition* candidate )
PartitionTable* table = dynamic_cast< PartitionTable* >( candidate->parent() ); PartitionTable* table = dynamic_cast< PartitionTable* >( candidate->parent() );
if ( !table ) if ( !table )
{ {
cDebug() << Logger::SubEntry() << "NO, no partition table found"; cDebug() << Logger::SubEntry << "NO, no partition table found";
return false; return false;
} }
if ( table->numPrimaries() >= table->maxPrimaries() ) if ( table->numPrimaries() >= table->maxPrimaries() )
{ {
cDebug() << Logger::SubEntry() << "NO, partition table already has" cDebug() << Logger::SubEntry << "NO, partition table already has"
<< table->maxPrimaries() << "primary partitions."; << table->maxPrimaries() << "primary partitions.";
return false; return false;
} }
@ -164,10 +164,10 @@ canBeResized( Partition* candidate )
else if ( ok ) else if ( ok )
{ {
auto deb = cDebug(); auto deb = cDebug();
deb << Logger::SubEntry() << "NO, insufficient storage"; deb << Logger::SubEntry << "NO, insufficient storage";
deb << Logger::Continuation() << "Required storage B:" << advisedStorageB deb << Logger::Continuation << "Required storage B:" << advisedStorageB
<< QString( "(%1GB)" ).arg( advisedStorageGB ); << QString( "(%1GB)" ).arg( advisedStorageGB );
deb << Logger::Continuation() << "Available storage B:" << availableStorageB deb << Logger::Continuation << "Available storage B:" << availableStorageB
<< QString( "(%1GB)" ).arg( availableStorageB / 1024 / 1024 / 1024 ) << QString( "(%1GB)" ).arg( availableStorageB / 1024 / 1024 / 1024 )
<< "for" << convenienceName( candidate ) << " length:" << candidate->length() << "for" << convenienceName( candidate ) << " length:" << candidate->length()
<< " sectorsUsed:" << candidate->sectorsUsed() << " fsType:" << candidate->fileSystem().name(); << " sectorsUsed:" << candidate->sectorsUsed() << " fsType:" << candidate->fileSystem().name();
@ -175,7 +175,7 @@ canBeResized( Partition* candidate )
} }
else else
{ {
cDebug() << Logger::SubEntry() << "NO, requiredStorageGB is not set correctly."; cDebug() << Logger::SubEntry << "NO, requiredStorageGB is not set correctly.";
return false; return false;
} }
} }
@ -198,10 +198,10 @@ canBeResized( PartitionCoreModule* core, const QString& partitionPath )
return canBeResized( candidate ); return canBeResized( candidate );
} }
} }
cDebug() << Logger::SubEntry() << "no Partition* found for" << partitionWithOs; cDebug() << Logger::SubEntry << "no Partition* found for" << partitionWithOs;
} }
cDebug() << Logger::SubEntry() << "Partition" << partitionWithOs << "CANNOT BE RESIZED FOR AUTOINSTALL."; cDebug() << Logger::SubEntry << "Partition" << partitionWithOs << "CANNOT BE RESIZED FOR AUTOINSTALL.";
return false; return false;
} }

View File

@ -1238,12 +1238,12 @@ ChoicePage::setupActions()
{ {
if ( PartUtils::canBeResized( *it ) ) if ( PartUtils::canBeResized( *it ) )
{ {
cDebug() << Logger::SubEntry() << "contains resizable" << it; cDebug() << Logger::SubEntry << "contains resizable" << it;
atLeastOneCanBeResized = true; atLeastOneCanBeResized = true;
} }
if ( PartUtils::canBeReplaced( *it ) ) if ( PartUtils::canBeReplaced( *it ) )
{ {
cDebug() << Logger::SubEntry() << "contains replaceable" << it; cDebug() << Logger::SubEntry << "contains replaceable" << it;
atLeastOneCanBeReplaced = true; atLeastOneCanBeReplaced = true;
} }
if ( (*it)->isMounted() ) if ( (*it)->isMounted() )