diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,3 +101,5 @@ feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) + +install(FILES kconfig.categories DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR}) diff --git a/kconfig.categories b/kconfig.categories new file mode 100644 --- /dev/null +++ b/kconfig.categories @@ -0,0 +1 @@ +kf5.kconfig.core KConfig Core DEFAULT_SEVERITY [WARNING] IDENTIFIER [KCONFIG_CORE_LOG] diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -13,6 +13,11 @@ kconfigwatcher.cpp ) +ecm_qt_declare_logging_category(libkconfigcore_SRCS + HEADER kconfig_core_log_settings.h + IDENTIFIER KCONFIG_CORE_LOG + CATEGORY_NAME kf5.kconfig.core) + configure_file(config-kconfig.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-kconfig.h ) add_library(KF5ConfigCore ${libkconfigcore_SRCS}) diff --git a/src/core/kconfig.cpp b/src/core/kconfig.cpp --- a/src/core/kconfig.cpp +++ b/src/core/kconfig.cpp @@ -24,6 +24,7 @@ #include "kconfig_p.h" #include "config-kconfig.h" +#include "kconfig_core_log_settings.h" #include #include @@ -408,7 +409,7 @@ // lock the local file if (d->configState == ReadWrite && !d->lockLocal()) { - qWarning() << "couldn't lock local file"; + qCWarning(KCONFIG_CORE_LOG) << "couldn't lock local file"; return false; } @@ -438,7 +439,7 @@ if (d->wantGlobals() && writeGlobals) { QExplicitlySharedDataPointer tmp = KConfigBackend::create(*sGlobalFileName); if (d->configState == ReadWrite && !tmp->lock()) { - qWarning() << "couldn't lock global file"; + qCWarning(KCONFIG_CORE_LOG) << "couldn't lock global file"; //unlock the local config if we're returning early if (d->mBackend->isLocked()) { diff --git a/src/core/kconfiggroup.cpp b/src/core/kconfiggroup.cpp --- a/src/core/kconfiggroup.cpp +++ b/src/core/kconfiggroup.cpp @@ -25,6 +25,7 @@ #include "kconfig.h" #include "kconfig_p.h" +#include "kconfig_core_log_settings.h" #include "ksharedconfig.h" #include "kconfigdata.h" @@ -260,7 +261,7 @@ const auto list = asIntList(value); if (list.count() != 2) { - qWarning() << errString(pKey, value, aDefault) + qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault) << formatError(2, list.count()); return aDefault; } @@ -270,7 +271,7 @@ const auto list = asRealList(value); if (list.count() != 2) { - qWarning() << errString(pKey, value, aDefault) + qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault) << formatError(2, list.count()); return aDefault; } @@ -280,74 +281,74 @@ const auto list = asIntList(value); if (list.count() != 4) { - qWarning() << errString(pKey, value, aDefault) + qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault) << formatError(4, list.count()); return aDefault; } const QRect rect(list.at(0), list.at(1), list.at(2), list.at(3)); if (!rect.isValid()) { - qWarning() << errString(pKey, value, aDefault); + qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault); return aDefault; } return rect; } case QMetaType::QRectF: { const auto list = asRealList(value); if (list.count() != 4) { - qWarning() << errString(pKey, value, aDefault) + qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault) << formatError(4, list.count()); return aDefault; } const QRectF rect(list.at(0), list.at(1), list.at(2), list.at(3)); if (!rect.isValid()) { - qWarning() << errString(pKey, value, aDefault); + qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault); return aDefault; } return rect; } case QMetaType::QSize: { const auto list = asIntList(value); if (list.count() != 2) { - qWarning() << errString(pKey, value, aDefault) + qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault) << formatError(2, list.count()); return aDefault; } const QSize size(list.at(0), list.at(1)); if (!size.isValid()) { - qWarning() << errString(pKey, value, aDefault); + qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault); return aDefault; } return size; } case QMetaType::QSizeF: { const auto list = asRealList(value); if (list.count() != 2) { - qWarning() << errString(pKey, value, aDefault) + qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault) << formatError(2, list.count()); return aDefault; } const QSizeF size(list.at(0), list.at(1)); if (!size.isValid()) { - qWarning() << errString(pKey, value, aDefault); + qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault); return aDefault; } return size; } case QMetaType::QDateTime: { const auto list = asIntList(value); if (list.count() != 6) { - qWarning() << errString(pKey, value, aDefault) + qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault) << formatError(6, list.count()); return aDefault; } const QDate date(list.at(0), list.at(1), list.at(2)); const QTime time(list.at(3), list.at(4), list.at(5)); const QDateTime dt(date, time); if (!dt.isValid()) { - qWarning() << errString(pKey, value, aDefault); + qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault); return aDefault; } return dt; @@ -358,20 +359,20 @@ list = list.mid(0, 3); // don't break config files that stored QDate as QDateTime } if (list.count() != 3) { - qWarning() << errString(pKey, value, aDefault) + qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault) << formatError(3, list.count()); return aDefault; } const QDate date(list.at(0), list.at(1), list.at(2)); if (!date.isValid()) { - qWarning() << errString(pKey, value, aDefault); + qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault); return aDefault; } return date; } case QMetaType::QColor: case QMetaType::QFont: - qWarning() << "KConfigGroup::readEntry was passed GUI type '" + qCWarning(KCONFIG_CORE_LOG) << "KConfigGroup::readEntry was passed GUI type '" << aDefault.typeName() << "' but KConfigGui isn't linked! If it is linked to your program, " "this is a platform bug. Please inform the KDE developers"; @@ -383,7 +384,7 @@ break; } - qWarning() << "unhandled type " << aDefault.typeName(); + qCWarning(KCONFIG_CORE_LOG) << "unhandled type " << aDefault.typeName(); return QVariant(); } @@ -955,7 +956,7 @@ break; case QMetaType::QVariantList: if (!value.canConvert(QMetaType::QStringList)) - qWarning() << "not all types in \"" << key << "\" can convert to QString," + qCWarning(KCONFIG_CORE_LOG) << "not all types in \"" << key << "\" can convert to QString," " information will be lost"; Q_FALLTHROUGH(); case QMetaType::QStringList: @@ -1065,16 +1066,16 @@ case QMetaType::QColor: case QMetaType::QFont: - qWarning() << "KConfigGroup::writeEntry was passed GUI type '" + qCWarning(KCONFIG_CORE_LOG) << "KConfigGroup::writeEntry was passed GUI type '" << value.typeName() << "' but KConfigGui isn't linked! If it is linked to your program, this is a platform bug. " "Please inform the KDE developers"; break; case QMetaType::QUrl: data = QUrl(value.toUrl()).toString().toUtf8(); break; default: - qWarning() << "KConfigGroup::writeEntry - unhandled type" << value.typeName() << "in group" << name(); + qCWarning(KCONFIG_CORE_LOG) << "KConfigGroup::writeEntry - unhandled type" << value.typeName() << "in group" << name(); } writeEntry(key, data, flags); diff --git a/src/core/kconfigini.cpp b/src/core/kconfigini.cpp --- a/src/core/kconfigini.cpp +++ b/src/core/kconfigini.cpp @@ -26,6 +26,7 @@ #include "kconfigbackend_p.h" #include "bufferfragment_p.h" #include "kconfigdata.h" +#include "kconfig_core_log_settings.h" #include #include @@ -139,7 +140,7 @@ end = start; for (;;) { if (end == line.length()) { - qWarning() << warningProlog(file, lineNo) << "Invalid group header."; + qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, lineNo) << "Invalid group header."; // XXX maybe reset the current group here? goto next_line; } @@ -196,7 +197,7 @@ line.trim(); } if (aKey.isEmpty()) { - qWarning() << warningProlog(file, lineNo) << "Invalid entry (empty key)"; + qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, lineNo) << "Invalid entry (empty key)"; continue; } @@ -210,7 +211,7 @@ while ((start = aKey.lastIndexOf('[')) >= 0) { int end = aKey.indexOf(']', start); if (end < 0) { - qWarning() << warningProlog(file, lineNo) + qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, lineNo) << "Invalid entry (missing ']')"; goto next_line; } else if (end > start + 1 && aKey.at(start + 1) == '$') { // found option(s) @@ -240,7 +241,7 @@ } } else { // found a locale if (!locale.isNull()) { - qWarning() << warningProlog(file, lineNo) + qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, lineNo) << "Invalid entry (second locale!?)"; goto next_line; } @@ -250,7 +251,7 @@ aKey.truncate(start); } if (eqpos < 0) { // Do this here after [$d] was checked - qWarning() << warningProlog(file, lineNo) << "Invalid entry (missing '=')"; + qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, lineNo) << "Invalid entry (missing '=')"; continue; } printableToString(&aKey, file, lineNo); @@ -511,7 +512,7 @@ return true; } // Couldn't write. Disk full? - qWarning() << "Couldn't write" << filePath() << ". Disk full?"; + qCWarning(KCONFIG_CORE_LOG) << "Couldn't write" << filePath() << ". Disk full?"; return false; } } else { @@ -855,7 +856,7 @@ } else { QByteArray e(str, 2); e.prepend("\\x"); - qWarning() << warningProlog(file, line) << "Invalid hex character " << c + qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, line) << "Invalid hex character " << c << " in \\x-type escape sequence \"" << e.constData() << "\"."; return 'x'; } @@ -923,7 +924,7 @@ break; default: *r = '\\'; - qWarning() << warningProlog(file, line) + qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, line) << QStringLiteral("Invalid escape sequence \"\\%1\".").arg(str[i]); } } diff --git a/src/core/kconfigwatcher.cpp b/src/core/kconfigwatcher.cpp --- a/src/core/kconfigwatcher.cpp +++ b/src/core/kconfigwatcher.cpp @@ -20,6 +20,7 @@ #include "kconfigwatcher.h" #include "config-kconfig.h" +#include "kconfig_core_log_settings.h" #if KCONFIG_USE_DBUS #include @@ -85,7 +86,7 @@ SLOT(onConfigChangeNotification(QHash))); } #else - qWarning() << "Use of KConfigWatcher without DBus support. You will not receive updates"; + qCWarning(KCONFIG_CORE_LOG) << "Use of KConfigWatcher without DBus support. You will not receive updates"; #endif } diff --git a/src/core/kdesktopfile.cpp b/src/core/kdesktopfile.cpp --- a/src/core/kdesktopfile.cpp +++ b/src/core/kdesktopfile.cpp @@ -34,6 +34,7 @@ #include "kconfig_p.h" #include "kconfiggroup.h" #include "kconfigini_p.h" +#include "kconfig_core_log_settings.h" class KDesktopFilePrivate : public KConfigPrivate { @@ -158,7 +159,7 @@ // Forbid desktop files outside of standard locations if kiosk is set so if (!KAuthorized::authorize(QStringLiteral("run_desktop_files"))) { - qWarning() << "Access to '" << path << "' denied because of 'run_desktop_files' restriction." << endl; + qCWarning(KCONFIG_CORE_LOG) << "Access to '" << path << "' denied because of 'run_desktop_files' restriction." << endl; return false; } @@ -169,7 +170,7 @@ return true; } - qWarning() << "Access to '" << path << "' denied, not owned by root, executable flag not set." << endl; + qCWarning(KCONFIG_CORE_LOG) << "Access to '" << path << "' denied, not owned by root, executable flag not set." << endl; return false; }