From 09ae721038069850a6d4380b54870e0220b188fe Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 4 Apr 2019 14:32:36 +0200 Subject: [PATCH] [libcalamares] Structure continuations and sub-entries --- src/libcalamares/utils/Logger.cpp | 31 ++++++++++++++++++++++++++- src/libcalamares/utils/Logger.h | 35 ++++++++++++++++++++++++++----- 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/src/libcalamares/utils/Logger.cpp b/src/libcalamares/utils/Logger.cpp index b75fb6495..31dd44978 100644 --- a/src/libcalamares/utils/Logger.cpp +++ b/src/libcalamares/utils/Logger.cpp @@ -189,7 +189,36 @@ CDebug::~CDebug() { } -const char* continuation = "\n "; +static const char continuation[] = "\n "; +static const char subentry[] = " .. "; + +QDebug& +operator<<( QDebug& s, Continuation c ) +{ + s << continuation; + return s; +} + +QDebug& +operator<<( QDebug& s, SubEntry l ) +{ + s << subentry; + return s; +} + +CDebug& +operator<<( CDebug&& s, Continuation c ) +{ + s << continuation; + return s; +} + +CDebug& +operator<<( CDebug&& s, SubEntry l ) +{ + s << subentry; + return s; +} QString toString( const QVariant& v ) { diff --git a/src/libcalamares/utils/Logger.h b/src/libcalamares/utils/Logger.h index 0cb4b494f..d3861279e 100644 --- a/src/libcalamares/utils/Logger.h +++ b/src/libcalamares/utils/Logger.h @@ -2,7 +2,7 @@ * * Copyright 2010-2011, Christian Muehlhaeuser * Copyright 2014, Teo Mrnjavac - * Copyright 2017-2018, Adriaan de Groot + * Copyright 2017-2019, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,7 +27,25 @@ namespace Logger { - extern const char* continuation; + /** @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 + { + } ; enum { @@ -95,6 +113,13 @@ 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. * @@ -161,7 +186,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; } @@ -170,7 +195,7 @@ namespace Logger operator <<( QDebug& s, const DebugList& c ) { for( const auto& i : c.list ) - s << continuation << i; + s << Continuation() << i; return s; } @@ -182,7 +207,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; } }