aboutsummaryrefslogtreecommitdiff
path: root/lib/logging.h
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2021-11-19 12:45:50 +0100
committerAlexey Rusakov <Kitsune-Ral@users.sf.net>2021-11-19 12:45:50 +0100
commitd6cf6b32cdd2843c40fc696accd8a6456f1ea15c (patch)
tree8299df2f413749badf90a96f92e2866976acc6cb /lib/logging.h
parent76b6238af16a1ccd284831ce42ec9e2cb1fba2c5 (diff)
downloadlibquotient-d6cf6b32cdd2843c40fc696accd8a6456f1ea15c.tar.gz
libquotient-d6cf6b32cdd2843c40fc696accd8a6456f1ea15c.zip
Make enum values logging more terse()
By default enum class values are logged along with the qualifier; this may or may not be desirable in a given setting. For JoinState(s) and Membership(Mask) operator<< was overloaded to implicitly suppress qualification; however, this is both overly sweeping and uses Qt's internal API for the backend. Instead, a new QDebug manipulator, terse(), is introduced, that does the same as those operator<< overloads but on a per-invocation basis. This makes it slightly more verbose to log enums but makes the QDebug reconfiguration explicit and doesn't require to produce new overloads every time a new enum ends up in logs. And it's built entirely on the published Qt API, reusing the QDebugManip framework that Quotient already has. Also: operator<<(QDebug, QDebugManip) has been moved out of the namespace to fix lookup issues when there's no prior `using namespace Quotient`.
Diffstat (limited to 'lib/logging.h')
-rw-r--r--lib/logging.h31
1 files changed, 21 insertions, 10 deletions
diff --git a/lib/logging.h b/lib/logging.h
index 5a3ef6ea..5bf050a9 100644
--- a/lib/logging.h
+++ b/lib/logging.h
@@ -40,17 +40,15 @@ inline QDebug formatJson(QDebug debug_object)
return debug_object.noquote();
}
-/**
- * @brief A helper operator to facilitate usage of formatJson (and possibly
- * other manipulators)
- *
- * @param debug_object to output the json to
- * @param qdm a QDebug manipulator
- * @return a copy of debug_object that has its mode altered by qdm
- */
-inline QDebug operator<<(QDebug debug_object, QDebugManip qdm)
+//! Suppress full qualification of enums/QFlags when logging
+inline QDebug terse(QDebug dbg)
{
- return qdm(debug_object);
+ return
+#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
+ dbg.setVerbosity(0), dbg;
+#else
+ dbg.verbosity(QDebug::MinimumVerbosity);
+#endif
}
inline qint64 profilerMinNsecs()
@@ -65,6 +63,19 @@ inline qint64 profilerMinNsecs()
}
} // namespace Quotient
+/**
+ * @brief A helper operator to facilitate usage of formatJson (and possibly
+ * other manipulators)
+ *
+ * @param debug_object to output the json to
+ * @param qdm a QDebug manipulator
+ * @return a copy of debug_object that has its mode altered by qdm
+ */
+inline QDebug operator<<(QDebug debug_object, Quotient::QDebugManip qdm)
+{
+ return qdm(debug_object);
+}
+
inline QDebug operator<<(QDebug debug_object, const QElapsedTimer& et)
{
auto val = et.nsecsElapsed() / 1000;