From 6d54fcbe94c4f8c52054f59db7cb153df1dc820d Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Mon, 24 Oct 2022 00:33:05 +0300 Subject: [PATCH] kdecore: simplify and unexport KDebug internals Signed-off-by: Ivailo Monev --- kdecore/io/kdebug.cpp | 53 ++++++++++++++++----------------- kdecore/io/kdebug.h | 69 +++++-------------------------------------- 2 files changed, 33 insertions(+), 89 deletions(-) diff --git a/kdecore/io/kdebug.cpp b/kdecore/io/kdebug.cpp index 16df29b0..f32b0507 100644 --- a/kdecore/io/kdebug.cpp +++ b/kdecore/io/kdebug.cpp @@ -45,11 +45,8 @@ static int s_kde_debug_methodname = -1; static int s_kde_debug_timestamp = -1; static int s_kde_debug_color = -1; -static QByteArray kDebugHeader(const QByteArray &areaname, const char* const file, const int line, const char* const funcinfo) +static QByteArray kDebugHeader(const QByteArray &areaname, const char* const funcinfo) { - Q_UNUSED(file); - Q_UNUSED(line); - if (s_kde_debug_methodname == -1) { s_kde_debug_methodname = !qgetenv("KDE_DEBUG_METHODNAME").isEmpty(); } @@ -486,7 +483,21 @@ QString kBacktrace(int levels) #endif // HAVE_BACKTRACE } -QDebug kDebugStream(QtMsgType level, int area, const char *file, int line, const char *funcinfo) +void kClearDebugConfig() +{ + QMutexLocker locker(globalKDebugMutex); + + globalKDebugDevices->destroyDevices(); + + globalKDebugConfig->reparseConfiguration(); + globalKDebugConfig->cacheAreas(); + + s_kde_debug_methodname = -1; + s_kde_debug_timestamp = -1; + s_kde_debug_color = -1; +} + +QDebug KDebug(const QtMsgType type, const char* const funcinfo, const int area) { QMutexLocker locker(globalKDebugMutex); @@ -499,7 +510,7 @@ QDebug kDebugStream(QtMsgType level, int area, const char *file, int line, const QString areafilename; // TODO: abort when? can't show message box and abort immediately bool areaabort = true; - switch (level) { + switch (type) { case QtDebugMsg: { areaoutput = kdebugareacache.infooutput; areafilename = kdebugareacache.infofilename; @@ -532,8 +543,8 @@ QDebug kDebugStream(QtMsgType level, int area, const char *file, int line, const globalKDebugDevices->insert(areakey, qiodevice); } KDebugFileDevice* kdebugdevice = qobject_cast(qiodevice); - kdebugdevice->setLevel(level); - kdebugdevice->setHeader(kDebugHeader(globalKDebugConfig->areaName(area), file, line, funcinfo)); + kdebugdevice->setLevel(type); + kdebugdevice->setHeader(kDebugHeader(globalKDebugConfig->areaName(area), funcinfo)); kdebugdevice->setFilepath(areafilename); return QDebug(kdebugdevice); } @@ -544,8 +555,8 @@ QDebug kDebugStream(QtMsgType level, int area, const char *file, int line, const globalKDebugDevices->insert(areakey, qiodevice); } KDebugMessageBoxDevice* kdebugdevice = qobject_cast(qiodevice); - kdebugdevice->setLevel(level); - kdebugdevice->setHeader(kDebugHeader(globalKDebugConfig->areaName(area), file, line, funcinfo)); + kdebugdevice->setLevel(type); + kdebugdevice->setHeader(kDebugHeader(globalKDebugConfig->areaName(area), funcinfo)); return QDebug(kdebugdevice); } case KDebugConfig::TypeShell: { @@ -555,8 +566,8 @@ QDebug kDebugStream(QtMsgType level, int area, const char *file, int line, const globalKDebugDevices->insert(areakey, qiodevice); } KDebugShellDevice* kdebugdevice = qobject_cast(qiodevice); - kdebugdevice->setLevel(level); - kdebugdevice->setHeader(kDebugHeader(globalKDebugConfig->areaName(area), file, line, funcinfo)); + kdebugdevice->setLevel(type); + kdebugdevice->setHeader(kDebugHeader(globalKDebugConfig->areaName(area), funcinfo)); return QDebug(kdebugdevice); } case KDebugConfig::TypeSyslog: { @@ -566,8 +577,8 @@ QDebug kDebugStream(QtMsgType level, int area, const char *file, int line, const globalKDebugDevices->insert(areakey, qiodevice); } KDebugSyslogDevice* kdebugdevice = qobject_cast(qiodevice); - kdebugdevice->setLevel(level); - kdebugdevice->setHeader(kDebugHeader(globalKDebugConfig->areaName(area), file, line, funcinfo)); + kdebugdevice->setLevel(type); + kdebugdevice->setHeader(kDebugHeader(globalKDebugConfig->areaName(area), funcinfo)); return QDebug(kdebugdevice); } case KDebugConfig::TypeOff: @@ -578,20 +589,6 @@ QDebug kDebugStream(QtMsgType level, int area, const char *file, int line, const Q_UNREACHABLE(); } -void kClearDebugConfig() -{ - QMutexLocker locker(globalKDebugMutex); - - globalKDebugDevices->destroyDevices(); - - globalKDebugConfig->reparseConfiguration(); - globalKDebugConfig->cacheAreas(); - - s_kde_debug_methodname = -1; - s_kde_debug_timestamp = -1; - s_kde_debug_color = -1; -} - QDebug operator<<(QDebug s, const KDateTime &time) { if ( time.isDateOnly() ) diff --git a/kdecore/io/kdebug.h b/kdecore/io/kdebug.h index 30c6b6e7..3cab25e5 100644 --- a/kdecore/io/kdebug.h +++ b/kdecore/io/kdebug.h @@ -35,13 +35,6 @@ * output and when it is TTY */ -/** - * @internal - * Returns a debug stream that may or may not output anything. - */ -KDECORE_EXPORT QDebug kDebugStream(QtMsgType level, int area, const char *file = 0, - int line = -1, const char *funcinfo = 0); - /** * \relates KGlobal * Returns a backtrace. @@ -89,37 +82,11 @@ KDECORE_EXPORT void kClearDebugConfig(); * \relates KGlobal * Returns a debug stream. You can use it to print debug * information. - * @param area an id to identify the output, KDE_DEFAULT_DEBUG_AREA for default + * @param type type of message + * @param funcinfo caller of KDebug + * @param area an id to identify the output */ -static inline QDebug kDebug(int area = KDE_DEFAULT_DEBUG_AREA) -{ return kDebugStream(QtDebugMsg, area); } - -/** - * \relates KGlobal - * Returns a warning stream. You can use it to print warning - * information. - * @param area an id to identify the output, KDE_DEFAULT_DEBUG_AREA for default - */ -static inline QDebug kWarning(int area = KDE_DEFAULT_DEBUG_AREA) -{ return kDebugStream(QtWarningMsg, area); } - -/** - * \relates KGlobal - * Returns an error stream. You can use it to print error - * information. - * @param area an id to identify the output, KDE_DEFAULT_DEBUG_AREA for default - */ -static inline QDebug kError(int area = KDE_DEFAULT_DEBUG_AREA) -{ return kDebugStream(QtCriticalMsg, area); } - -/** - * \relates KGlobal - * Returns a fatal error stream. You can use it to print fatal error - * information. - * @param area an id to identify the output, KDE_DEFAULT_DEBUG_AREA for default - */ -static inline QDebug kFatal(int area = KDE_DEFAULT_DEBUG_AREA) -{ return kDebugStream(QtFatalMsg, area); } +KDECORE_EXPORT QDebug KDebug(const QtMsgType type, const char* const funcinfo, const int area = KDE_DEFAULT_DEBUG_AREA); // operators for KDE types class KUrl; @@ -127,30 +94,10 @@ class KDateTime; KDECORE_EXPORT QDebug operator<<(QDebug s, const KUrl &url); KDECORE_EXPORT QDebug operator<<(QDebug s, const KDateTime &time); -/** - * @internal - * A class for using operator() - */ -class KDebug -{ - const char* const file; - const char* const funcinfo; - const int line; - const QtMsgType level; -public: - explicit inline KDebug(QtMsgType type, const char* const f = 0, int l = -1, const char* const info = 0) - : file(f), funcinfo(info), line(l), level(type) - { - } - - inline QDebug operator()(int area = KDE_DEFAULT_DEBUG_AREA) - { return kDebugStream(level, area, file, line, funcinfo); } -}; - -#define kDebug KDebug(QtDebugMsg, __FILE__, __LINE__, Q_FUNC_INFO) -#define kWarning KDebug(QtWarningMsg, __FILE__, __LINE__, Q_FUNC_INFO) -#define kError KDebug(QtCriticalMsg, __FILE__, __LINE__, Q_FUNC_INFO) -#define kFatal KDebug(QtFatalMsg, __FILE__, __LINE__, Q_FUNC_INFO) +#define kDebug(...) KDebug(QtDebugMsg, Q_FUNC_INFO, ##__VA_ARGS__) +#define kWarning(...) KDebug(QtWarningMsg, Q_FUNC_INFO, ##__VA_ARGS__) +#define kError(...) KDebug(QtCriticalMsg, Q_FUNC_INFO, ##__VA_ARGS__) +#define kFatal(...) KDebug(QtFatalMsg, Q_FUNC_INFO, ##__VA_ARGS__) /** * Convenience macro, use this to remind yourself to finish the implementation of a function