From f0fd47eeb31de923cc6bad6384d888c26f17e5ec Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 26 Jan 2021 00:13:10 +0100 Subject: [PATCH] [libcalamares] Simplify logging-manipulators Writing `Logger::NoQuote{}`` has annoyed me for a while, so switch it to a constant, like SubEntry, so it looks more like a regular manipulator object. --- src/libcalamares/utils/CalamaresUtilsSystem.cpp | 8 ++++---- src/libcalamares/utils/Logger.cpp | 2 ++ src/libcalamares/utils/Logger.h | 12 +++++++----- src/libcalamaresui/Branding.cpp | 2 +- src/libcalamaresui/ViewManager.cpp | 6 +++--- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/libcalamares/utils/CalamaresUtilsSystem.cpp b/src/libcalamares/utils/CalamaresUtilsSystem.cpp index 841d52969..29f743743 100644 --- a/src/libcalamares/utils/CalamaresUtilsSystem.cpp +++ b/src/libcalamares/utils/CalamaresUtilsSystem.cpp @@ -188,7 +188,7 @@ System::runCommand( System::RunLocation location, : -1 ) ) { cWarning() << "Process" << args.first() << "timed out after" << timeoutSec.count() << "s. Output so far:\n" - << Logger::NoQuote {} << process.readAllStandardOutput(); + << Logger::NoQuote << process.readAllStandardOutput(); return ProcessResult::Code::TimedOut; } @@ -196,7 +196,7 @@ System::runCommand( System::RunLocation location, if ( process.exitStatus() == QProcess::CrashExit ) { - cWarning() << "Process" << args.first() << "crashed. Output so far:\n" << Logger::NoQuote {} << output; + cWarning() << "Process" << args.first() << "crashed. Output so far:\n" << Logger::NoQuote << output; return ProcessResult::Code::Crashed; } @@ -206,7 +206,7 @@ System::runCommand( System::RunLocation location, { if ( showDebug && !output.isEmpty() ) { - cDebug() << Logger::SubEntry << "Finished. Exit code:" << r << "output:\n" << Logger::NoQuote {} << output; + cDebug() << Logger::SubEntry << "Finished. Exit code:" << r << "output:\n" << Logger::NoQuote << output; } else { @@ -218,7 +218,7 @@ System::runCommand( System::RunLocation location, if ( !output.isEmpty() ) { cDebug() << Logger::SubEntry << "Target cmd:" << RedactedList( args ) << "Exit code:" << r << "output:\n" - << Logger::NoQuote {} << output; + << Logger::NoQuote << output; } else { diff --git a/src/libcalamares/utils/Logger.cpp b/src/libcalamares/utils/Logger.cpp index 0a7dcefd0..262ff59e1 100644 --- a/src/libcalamares/utils/Logger.cpp +++ b/src/libcalamares/utils/Logger.cpp @@ -207,6 +207,8 @@ constexpr FuncSuppressor::FuncSuppressor( const char s[] ) const constexpr FuncSuppressor Continuation( s_Continuation ); const constexpr FuncSuppressor SubEntry( s_SubEntry ); +const constexpr NoQuote_t NoQuote {}; +const constexpr Quote_t Quote {}; QString toString( const QVariant& v ) diff --git a/src/libcalamares/utils/Logger.h b/src/libcalamares/utils/Logger.h index 58603c82d..a53ab7e19 100644 --- a/src/libcalamares/utils/Logger.h +++ b/src/libcalamares/utils/Logger.h @@ -25,15 +25,17 @@ struct FuncSuppressor const char* m_s; }; -struct NoQuote +struct NoQuote_t { }; -struct Quote +struct Quote_t { }; DLLEXPORT extern const FuncSuppressor Continuation; DLLEXPORT extern const FuncSuppressor SubEntry; +DLLEXPORT extern const NoQuote_t NoQuote; +DLLEXPORT extern const Quote_t Quote; enum { @@ -74,13 +76,13 @@ operator<<( QDebug& s, const FuncSuppressor& f ) } inline QDebug& -operator<<( QDebug& s, const NoQuote& ) +operator<<( QDebug& s, const NoQuote_t& ) { return s.noquote().nospace(); } inline QDebug& -operator<<( QDebug& s, const Quote& ) +operator<<( QDebug& s, const Quote_t& ) { return s.quote().space(); } @@ -254,7 +256,7 @@ operator<<( QDebug& s, const DebugMap& t ) inline QDebug& operator<<( QDebug& s, const Pointer& p ) { - s << NoQuote {} << '@' << p.ptr << Quote {}; + s << NoQuote << '@' << p.ptr << Quote; return s; } } // namespace Logger diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index 8145ad57c..a5038d7ee 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -35,7 +35,7 @@ [[noreturn]] static void bail( const QString& descriptorPath, const QString& message ) { - cError() << "FATAL in" << descriptorPath << Logger::Continuation << Logger::NoQuote {} << message; + cError() << "FATAL in" << descriptorPath << Logger::Continuation << Logger::NoQuote << message; ::exit( EXIT_FAILURE ); } diff --git a/src/libcalamaresui/ViewManager.cpp b/src/libcalamaresui/ViewManager.cpp index f43152209..0614c786f 100644 --- a/src/libcalamaresui/ViewManager.cpp +++ b/src/libcalamaresui/ViewManager.cpp @@ -142,9 +142,9 @@ ViewManager::onInstallationFailed( const QString& message, const QString& detail { bool shouldOfferWebPaste = false; // TODO: config var - cError() << "Installation failed:"; - cDebug() << "- message:" << message; - cDebug() << "- details:" << details; + cError() << "Installation failed:" << message; + cDebug() << Logger::SubEntry << "- message:" << message; + cDebug() << Logger::SubEntry << "- details:" << Logger::NoQuote << details; QString heading = Calamares::Settings::instance()->isSetupMode() ? tr( "Setup Failed" ) : tr( "Installation Failed" );