From kde-core-devel Thu Dec 27 10:31:07 2007 From: Marc Mutz Date: Thu, 27 Dec 2007 10:31:07 +0000 To: kde-core-devel Subject: [PATCH] User-friendly kDebug (was: Re: KDE/kdepim/libkdepim) Message-Id: <200712271233.40122.marc () klaralvdalens-datakonsult ! se> X-MARC-Message: https://marc.info/?l=kde-core-devel&m=119875146731279 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--Boundary-00=_ku5cHRFyM0F0lXt" --Boundary-00=_ku5cHRFyM0F0lXt Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hei, I have seen lots of commits like this one in the recent past. On Saturday 22 December 2007 16:45, Thomas McGuire wrote: > Remove the home-brewn debug and warning functions, I got reports that > this breaks compilation in release mode. > > Shouldn't kDebug() have the same signature, regardless of whether > debug is turned on or off? > > It would also be great if dasbbot would do release builds from time > to time. > - warning() << "missing or empty [Plugin]Type value in \"" << *i= t=20 << "\" - skipping" << endl; >+ kWarning( 5300 ) << "missing or empty [Plugin]Type value in \""= <<=20 *it << "\" - skipping" << endl; But going around and removing helper functions that are supposed to localiz= e=20 the knowledge of debug areas isn't really helpful to people that try to wri= te=20 maintainable code. Please be aware of the following: In destroying good=20 patterns like this, you are destroying knowledge for the KDE community as a= =20 whole! However, if this pattern is causing trouble, maybe it's time to step back a= nd=20 reconsider the way we handle debug areas. Why do people use these helper functions? Nobody wants to remember the debug area for every application. It's a major= =20 PITA, in fact, to have to pass them to each kDebug/kWarning call. That's wh= y=20 people rightfully try to localize this knowledge. Are there other options? Yes. A much better approach is taken by libgpg-error: The error source is=20 GPG_ERR_SOURCE_DEFAULT, which can be redefined to a 'real' error source val= ue=20 by the build system or inside a single file, prior to #including the header= =20 file. It would be much more convenient if KDE adopted this (if there's stil= l=20 time): CMakeLists.txt + kde4_set_debug_area( 1234 ) # defines -DKDE_DEFAULT_DEBUG_AREA=3D1234 or= =20 similar foo.cpp: =2D kDebug( 1234 ) << "blah"; + kDebug() << "blah"; // uses 1234 The attached patch implements the (trivial) part for kdebug.h. Technically,= it=20 violates the ODR, but since it's just about static inline'ed functions=20 (except for KDebug::operator()s, which give me a ever-so-slight headache),= =20 and only ever about default arguments, it should be safe. If someone with more knowledge about where to put cmake macros would supply= =20 the kde4_set_debug_area() call (also trivial), I'd be delighted. Thanks, Marc =2D-=20 Marc Mutz -- marc@klaralvdalens-datakonsult.se, mutz@kde.org Klar=C3=A4lvdalens Datakonsult AB, Platform-independent software solutions --Boundary-00=_ku5cHRFyM0F0lXt Content-Type: text/x-diff; charset="utf-8"; name="kdebug.h.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="kdebug.h.diff" Index: kdecore/io/kdebug.h =================================================================== --- kdecore/io/kdebug.h (revision 753379) +++ kdecore/io/kdebug.h (working copy) @@ -106,6 +106,10 @@ */ KDECORE_EXPORT void kClearDebugConfig(); +#ifndef KDE_DEFAULT_DEBUG_AREA +# define KDE_DEFAULT_DEBUG_AREA 0 +#endif + #if !defined(KDE_NO_DEBUG_OUTPUT) /** * \relates KGlobal @@ -113,14 +117,14 @@ * information. * @param area an id to identify the output, 0 for default */ -static inline QDebug kDebug(int area = 0) +static inline QDebug kDebug(int area = KDE_DEFAULT_DEBUG_AREA) { return kDebugStream(QtDebugMsg, area); } -static inline QDebug kDebug(bool cond, int area = 0) +static inline QDebug kDebug(bool cond, int area = KDE_DEFAULT_DEBUG_AREA) { return cond ? kDebug(area) : kDebugDevNull(); } #else // KDE_NO_DEBUG_OUTPUT -static inline QDebug kDebug(int = 0) { return kDebugDevNull(); } -static inline QDebug kDebug(bool, int = 0) { return kDebugDevNull(); } +static inline QDebug kDebug(int = KDE_DEFAULT_DEBUG_AREA) { return kDebugDevNull(); } +static inline QDebug kDebug(bool, int = KDE_DEFAULT_DEBUG_AREA) { return kDebugDevNull(); } #endif #if !defined(KDE_NO_WARNING_OUTPUT) @@ -130,14 +134,14 @@ * information. * @param area an id to identify the output, 0 for default */ -static inline QDebug kWarning(int area = 0) +static inline QDebug kWarning(int area = KDE_DEFAULT_DEBUG_AREA) { return kDebugStream(QtWarningMsg, area); } -static inline QDebug kWarning(bool cond, int area = 0) +static inline QDebug kWarning(bool cond, int area = KDE_DEFAULT_DEBUG_AREA) { return cond ? kWarning(area) : kDebugDevNull(); } #else // KDE_NO_WARNING_OUTPUT -static inline QDebug kWarning(int = 0) { return kDebugDevNull(); } -static inline QDebug kWarning(bool, int = 0) { return kDebugDevNull(); } +static inline QDebug kWarning(int = KDE_DEFAULT_DEBUG_AREA) { return kDebugDevNull(); } +static inline QDebug kWarning(bool, int = KDE_DEFAULT_DEBUG_AREA) { return kDebugDevNull(); } #endif /** @@ -146,9 +150,9 @@ * information. * @param area an id to identify the output, 0 for default */ -static inline QDebug kError(int area = 0) +static inline QDebug kError(int area = KDE_DEFAULT_DEBUG_AREA) { return kDebugStream(QtCriticalMsg, area); } -static inline QDebug kError(bool cond, int area = 0) +static inline QDebug kError(bool cond, int area = KDE_DEFAULT_DEBUG_AREA) { return cond ? kError(area) : kDebugDevNull(); } /** @@ -157,9 +161,9 @@ * information. * @param area an id to identify the output, 0 for default */ -static inline QDebug kFatal(int area = 0) +static inline QDebug kFatal(int area = KDE_DEFAULT_DEBUG_AREA) { return kDebugStream(QtFatalMsg, area); } -static inline QDebug kFatal(bool cond, int area = 0) +static inline QDebug kFatal(bool cond, int area = KDE_DEFAULT_DEBUG_AREA) { return cond ? kFatal(area) : kDebugDevNull(); } struct KDebugTag { }; ///! @internal just a tag class @@ -187,10 +191,10 @@ class KDE_DEPRECATED kndbgstream { }; typedef QDebug kdbgstream; -static inline KDE_DEPRECATED QDebug kdDebug(int area = 0) { return kDebug(area); } -static inline KDE_DEPRECATED QDebug kdWarning(int area = 0) { return kWarning(area); } -static inline KDE_DEPRECATED QDebug kdError(int area = 0) { return kError(area); } -static inline KDE_DEPRECATED QDebug kdFatal(int area = 0) { return kFatal(area); } +static inline KDE_DEPRECATED QDebug kdDebug(int area = KDE_DEFAULT_DEBUG_AREA) { return kDebug(area); } +static inline KDE_DEPRECATED QDebug kdWarning(int area = KDE_DEFAULT_DEBUG_AREA) { return kWarning(area); } +static inline KDE_DEPRECATED QDebug kdError(int area = KDE_DEFAULT_DEBUG_AREA) { return kError(area); } +static inline KDE_DEPRECATED QDebug kdFatal(int area = KDE_DEFAULT_DEBUG_AREA) { return kFatal(area); } static inline KDE_DEPRECATED QString kdBacktrace(int levels=-1) { return kBacktrace( levels ); } static inline KDE_DEPRECATED QDebug kndDebug() { return kDebugDevNull(); } @@ -210,9 +214,9 @@ explicit inline KDebug(QtMsgType type, const char *f = 0, int l = -1, const char *info = 0) : file(f), funcinfo(info), line(l), level(type) { } - inline QDebug operator()(int area = 0) + inline QDebug operator()(int area = KDE_DEFAULT_DEBUG_AREA) { return kDebugStream(level, area, file, line, funcinfo); } - inline QDebug operator()(bool cond, int area = 0) + inline QDebug operator()(bool cond, int area = KDE_DEFAULT_DEBUG_AREA) { if (cond) return operator()(area); return kDebugDevNull(); } }; --Boundary-00=_ku5cHRFyM0F0lXt--