From d72e3b3c22b788008304d42b7f02f5014036243f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 15 Apr 2019 07:57:25 -0400 Subject: [PATCH 1/2] [libcalamares] Simplify writing of logging continuations - Instead of Continuation(), write just Continuation - All that futzing with overloads and tag-classes isn't needed since the whole point is to output some constant string. Leave cleverness for later, if it's needed. --- src/libcalamares/utils/Logger.cpp | 32 ++--------------------------- src/libcalamares/utils/Logger.h | 34 +++++-------------------------- 2 files changed, 7 insertions(+), 59 deletions(-) diff --git a/src/libcalamares/utils/Logger.cpp b/src/libcalamares/utils/Logger.cpp index 3061e0a5e..5f4401ca1 100644 --- a/src/libcalamares/utils/Logger.cpp +++ b/src/libcalamares/utils/Logger.cpp @@ -189,36 +189,8 @@ CDebug::~CDebug() { } -static const char continuation[] = "\n "; -static 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; -} +const char Continuation[] = "\n "; +const char SubEntry[] = " .. "; QString toString( const QVariant& v ) { diff --git a/src/libcalamares/utils/Logger.h b/src/libcalamares/utils/Logger.h index d3861279e..d7af886b3 100644 --- a/src/libcalamares/utils/Logger.h +++ b/src/libcalamares/utils/Logger.h @@ -27,25 +27,8 @@ namespace Logger { - /** @brief tag-class used for continuing debug-output on the next line - * - * 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 - { - } ; + DLLEXPORT extern const char Continuation[]; + DLLEXPORT extern const char SubEntry[]; enum { @@ -113,13 +96,6 @@ namespace Logger /** @brief Would the given @p level really be logged? */ 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. * @@ -186,7 +162,7 @@ namespace Logger inline QDebug& operator <<( QDebug& s, const DebugRow& t ) { - s << Continuation() << t.first << ':' << ' ' << t.second; + s << Continuation << t.first << ':' << ' ' << t.second; return s; } @@ -195,7 +171,7 @@ namespace Logger operator <<( QDebug& s, const DebugList& c ) { for( const auto& i : c.list ) - s << Continuation() << i; + s << Continuation << i; return s; } @@ -207,7 +183,7 @@ namespace Logger 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(); + s << Continuation << it.key().toUtf8().constData() << ':' << ' ' << toString( it.value() ).toUtf8().constData(); return s; } } From 63b317902d8bc1739fe5535fc75a494679ee6c14 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 15 Apr 2019 08:15:17 -0400 Subject: [PATCH 2/2] [libcalamares] [partition] Adjust to logging changes - Use the un-paren'ed Continuation and SubEntry --- src/libcalamares/Settings.cpp | 6 +++--- src/modules/partition/core/DeviceList.cpp | 12 ++++++------ src/modules/partition/core/PartUtils.cpp | 22 +++++++++++----------- src/modules/partition/gui/ChoicePage.cpp | 4 ++-- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/libcalamares/Settings.cpp b/src/libcalamares/Settings.cpp index 6f73b462b..710846a2c 100644 --- a/src/libcalamares/Settings.cpp +++ b/src/libcalamares/Settings.cpp @@ -44,7 +44,7 @@ requireString( const YAML::Node& config, const char* key ) return QString::fromStdString( v.as< std::string >() ); else { - cWarning() << Logger::SubEntry() << "Required settings.conf key" << key << "is missing."; + cWarning() << Logger::SubEntry << "Required settings.conf key" << key << "is missing."; return QString(); } } @@ -58,7 +58,7 @@ requireBool( const YAML::Node& config, const char* key, bool d ) return v.as< bool >(); else { - cWarning() << Logger::SubEntry() << "Required settings.conf key" << key << "is missing."; + cWarning() << Logger::SubEntry << "Required settings.conf key" << key << "is missing."; return d; } } @@ -106,7 +106,7 @@ interpretModulesSearch( const bool debugMode, const QStringList& rawPaths, QStri output.append( d.absolutePath() ); } else - cDebug() << Logger::SubEntry() << "module-search entry non-existent" << path; + cDebug() << Logger::SubEntry << "module-search entry non-existent" << path; } } } diff --git a/src/modules/partition/core/DeviceList.cpp b/src/modules/partition/core/DeviceList.cpp index a7f9ff44c..e9cc34138 100644 --- a/src/modules/partition/core/DeviceList.cpp +++ b/src/modules/partition/core/DeviceList.cpp @@ -116,7 +116,7 @@ QList< Device* > getDevices( DeviceType which, qint64 minimumSize ) #ifdef DEBUG_PARTITION_UNSAFE cWarning() << "Allowing unsafe partitioning choices." << devices.count() << "candidates."; #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 #else 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(); ) if ( !( *it ) ) { - cDebug() << Logger::SubEntry() << "Skipping nullptr device"; + cDebug() << Logger::SubEntry << "Skipping nullptr device"; it = erase( devices, it); } else if ( ( *it )->deviceNode().startsWith( "/dev/zram" ) ) { - cDebug() << Logger::SubEntry() << "Removing zram" << it; + cDebug() << Logger::SubEntry << "Removing zram" << it; it = erase( devices, 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 ); } 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 ); } 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 ); } else diff --git a/src/modules/partition/core/PartUtils.cpp b/src/modules/partition/core/PartUtils.cpp index cbbd63cbe..4feea0e38 100644 --- a/src/modules/partition/core/PartUtils.cpp +++ b/src/modules/partition/core/PartUtils.cpp @@ -109,20 +109,20 @@ canBeResized( Partition* candidate ) if ( !candidate->fileSystem().supportGrow() || !candidate->fileSystem().supportShrink() ) { - cDebug() << Logger::SubEntry() << "NO, filesystem" << candidate->fileSystem().name() + cDebug() << Logger::SubEntry << "NO, filesystem" << candidate->fileSystem().name() << "does not support resize."; return false; } if ( KPMHelpers::isPartitionFreeSpace( candidate ) ) { - cDebug() << Logger::SubEntry() << "NO, partition is free space"; + cDebug() << Logger::SubEntry << "NO, partition is free space"; return false; } if ( candidate->isMounted() ) { - cDebug() << Logger::SubEntry() << "NO, partition is mounted"; + cDebug() << Logger::SubEntry << "NO, partition is mounted"; return false; } @@ -131,13 +131,13 @@ canBeResized( Partition* candidate ) PartitionTable* table = dynamic_cast< PartitionTable* >( candidate->parent() ); if ( !table ) { - cDebug() << Logger::SubEntry() << "NO, no partition table found"; + cDebug() << Logger::SubEntry << "NO, no partition table found"; return false; } 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."; return false; } @@ -164,10 +164,10 @@ canBeResized( Partition* candidate ) else if ( ok ) { auto deb = cDebug(); - deb << Logger::SubEntry() << "NO, insufficient storage"; - deb << Logger::Continuation() << "Required storage B:" << advisedStorageB + deb << Logger::SubEntry << "NO, insufficient storage"; + deb << Logger::Continuation << "Required storage B:" << advisedStorageB << 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 ) << "for" << convenienceName( candidate ) << " length:" << candidate->length() << " sectorsUsed:" << candidate->sectorsUsed() << " fsType:" << candidate->fileSystem().name(); @@ -175,7 +175,7 @@ canBeResized( Partition* candidate ) } else { - cDebug() << Logger::SubEntry() << "NO, requiredStorageGB is not set correctly."; + cDebug() << Logger::SubEntry << "NO, requiredStorageGB is not set correctly."; return false; } } @@ -198,10 +198,10 @@ canBeResized( PartitionCoreModule* core, const QString& partitionPath ) 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; } diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index edeee11a6..fc57d1fad 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -1238,12 +1238,12 @@ ChoicePage::setupActions() { if ( PartUtils::canBeResized( *it ) ) { - cDebug() << Logger::SubEntry() << "contains resizable" << it; + cDebug() << Logger::SubEntry << "contains resizable" << it; atLeastOneCanBeResized = true; } if ( PartUtils::canBeReplaced( *it ) ) { - cDebug() << Logger::SubEntry() << "contains replaceable" << it; + cDebug() << Logger::SubEntry << "contains replaceable" << it; atLeastOneCanBeReplaced = true; } if ( (*it)->isMounted() )