From 0abde6f1a7d12a6910a8caa53ec23dd4c7df10e1 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 3 Mar 2020 16:59:26 +0100 Subject: [PATCH] [libcalamares] Don't print funcinfo in continuations - when a single function does more logging, it generally marks those as subsequent debug-messages (with Continuation, or SubEntry) and we don't need to print funcinfo for those, since it was already printed the first time. --- src/libcalamares/utils/Logger.cpp | 15 ++++++++++++--- src/libcalamares/utils/Logger.h | 25 +++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/libcalamares/utils/Logger.cpp b/src/libcalamares/utils/Logger.cpp index c39e73c50..ceca20b7a 100644 --- a/src/libcalamares/utils/Logger.cpp +++ b/src/libcalamares/utils/Logger.cpp @@ -44,6 +44,10 @@ static unsigned int s_threshold = #endif static QMutex s_mutex; +static const char s_Continuation[] = "\n "; +static const char s_SubEntry[] = " .. "; + + namespace Logger { @@ -192,14 +196,19 @@ CDebug::~CDebug() { if ( m_funcinfo ) { - m_msg.prepend( Continuation ); + m_msg.prepend( s_Continuation ); // Prepending, so back-to-front m_msg.prepend( m_funcinfo ); } log( m_msg.toUtf8().data(), m_debugLevel ); } -const char Continuation[] = "\n "; -const char SubEntry[] = " .. "; +constexpr FuncSuppressor::FuncSuppressor( const char s[] ) + : m_s( s ) +{ +} + +const constexpr FuncSuppressor Continuation( s_Continuation ); +const constexpr FuncSuppressor SubEntry( s_SubEntry ); QString toString( const QVariant& v ) diff --git a/src/libcalamares/utils/Logger.h b/src/libcalamares/utils/Logger.h index 2dfd2878f..fe4b98fd4 100644 --- a/src/libcalamares/utils/Logger.h +++ b/src/libcalamares/utils/Logger.h @@ -27,8 +27,14 @@ namespace Logger { -DLLEXPORT extern const char Continuation[]; -DLLEXPORT extern const char SubEntry[]; +struct FuncSuppressor +{ + explicit constexpr FuncSuppressor( const char[] ); + const char* m_s; +}; + +DLLEXPORT extern const FuncSuppressor Continuation; +DLLEXPORT extern const FuncSuppressor SubEntry; enum { @@ -47,12 +53,27 @@ public: explicit CDebug( unsigned int debugLevel = LOGDEBUG, const char* func = nullptr ); virtual ~CDebug(); + friend QDebug& operator<<( CDebug&&, const FuncSuppressor& ); + private: QString m_msg; unsigned int m_debugLevel; const char* m_funcinfo = nullptr; }; +inline QDebug& +operator<<( CDebug&& s, const FuncSuppressor& f ) +{ + s.m_funcinfo = nullptr; + return s << f.m_s; +} + +inline QDebug& +operator<<( QDebug& s, const FuncSuppressor& f ) +{ + return s << f.m_s; +} + /** * @brief The full path of the log file. */