[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    [PATCH] User-friendly kDebug (was: Re: KDE/kdepim/libkdepim)
From:       Marc Mutz <marc () klaralvdalens-datakonsult ! se>
Date:       2007-12-27 10:31:07
Message-ID: 200712271233.40122.marc () klaralvdalens-datakonsult ! se
[Download RAW message or body]

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.
<snip>
> -          warning() << "missing or empty [Plugin]Type value in \"" << *it 
<< "\" - skipping" << endl;
>+          kWarning( 5300 ) << "missing or empty [Plugin]Type value in \"" << 
*it << "\" - skipping" << endl;
<repeat a dozen times>

But going around and removing helper functions that are supposed to localize 
the knowledge of debug areas isn't really helpful to people that try to write 
maintainable code. Please be aware of the following: In destroying good 
patterns like this, you are destroying knowledge for the KDE community as a 
whole!

However, if this pattern is causing trouble, maybe it's time to step back and 
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 
PITA, in fact, to have to pass them to each kDebug/kWarning call. That's why 
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 
GPG_ERR_SOURCE_DEFAULT, which can be redefined to a 'real' error source value 
by the build system or inside a single file, prior to #including the header 
file. It would be much more convenient if KDE adopted this (if there's still 
time):

CMakeLists.txt
+ kde4_set_debug_area( 1234 ) # defines -DKDE_DEFAULT_DEBUG_AREA=1234 or 
similar

foo.cpp:
- kDebug( 1234 ) << "blah";
+ kDebug() << "blah"; // uses 1234

The attached patch implements the (trivial) part for kdebug.h. Technically, it 
violates the ODR, but since it's just about static inline'ed functions 
(except for KDebug::operator()s, which give me a ever-so-slight headache), 
and only ever about default arguments, it should be safe.

If someone with more knowledge about where to put cmake macros would supply 
the kde4_set_debug_area() call (also trivial), I'd be delighted.

Thanks,
Marc

-- 
Marc Mutz -- marc@klaralvdalens-datakonsult.se, mutz@kde.org
Klarälvdalens Datakonsult AB, Platform-independent software solutions

["kdebug.h.diff" (text/x-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(); }
 };
 



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic