Add a logging category for logs warnings

Summary: Disable logs unless the logging category kf5.kconfig.core is enabled

Test Plan: ctest

Reviewers: #frameworks, apol, cgiboudeaux

Reviewed By: cgiboudeaux

Subscribers: cgiboudeaux, mikeroyal, apol, kde-frameworks-devel

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D22061
wilder
Méven Car 7 years ago
parent 2de9e4fc16
commit 403c617eea
  1. 2
      CMakeLists.txt
  2. 1
      kconfig.categories
  3. 5
      src/core/CMakeLists.txt
  4. 5
      src/core/kconfig.cpp
  5. 39
      src/core/kconfiggroup.cpp
  6. 17
      src/core/kconfigini.cpp
  7. 3
      src/core/kconfigwatcher.cpp
  8. 5
      src/core/kdesktopfile.cpp

@ -101,3 +101,5 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kconfig_version.h
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
install(FILES kconfig.categories DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR})

@ -0,0 +1 @@
kf5.kconfig.core KConfig Core DEFAULT_SEVERITY [WARNING] IDENTIFIER [KCONFIG_CORE_LOG]

@ -13,6 +13,11 @@ set(libkconfigcore_SRCS
kconfigwatcher.cpp 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 ) configure_file(config-kconfig.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-kconfig.h )
add_library(KF5ConfigCore ${libkconfigcore_SRCS}) add_library(KF5ConfigCore ${libkconfigcore_SRCS})

@ -24,6 +24,7 @@
#include "kconfig_p.h" #include "kconfig_p.h"
#include "config-kconfig.h" #include "config-kconfig.h"
#include "kconfig_core_log_settings.h"
#include <cstdlib> #include <cstdlib>
#include <fcntl.h> #include <fcntl.h>
@ -408,7 +409,7 @@ bool KConfig::sync()
// lock the local file // lock the local file
if (d->configState == ReadWrite && !d->lockLocal()) { if (d->configState == ReadWrite && !d->lockLocal()) {
qWarning() << "couldn't lock local file"; qCWarning(KCONFIG_CORE_LOG) << "couldn't lock local file";
return false; return false;
} }
@ -438,7 +439,7 @@ bool KConfig::sync()
if (d->wantGlobals() && writeGlobals) { if (d->wantGlobals() && writeGlobals) {
QExplicitlySharedDataPointer<KConfigBackend> tmp = KConfigBackend::create(*sGlobalFileName); QExplicitlySharedDataPointer<KConfigBackend> tmp = KConfigBackend::create(*sGlobalFileName);
if (d->configState == ReadWrite && !tmp->lock()) { 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 //unlock the local config if we're returning early
if (d->mBackend->isLocked()) { if (d->mBackend->isLocked()) {

@ -25,6 +25,7 @@
#include "kconfig.h" #include "kconfig.h"
#include "kconfig_p.h" #include "kconfig_p.h"
#include "kconfig_core_log_settings.h"
#include "ksharedconfig.h" #include "ksharedconfig.h"
#include "kconfigdata.h" #include "kconfigdata.h"
@ -260,7 +261,7 @@ QVariant KConfigGroup::convertToQVariant(const char *pKey, const QByteArray &val
const auto list = asIntList(value); const auto list = asIntList(value);
if (list.count() != 2) { if (list.count() != 2) {
qWarning() << errString(pKey, value, aDefault) qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault)
<< formatError(2, list.count()); << formatError(2, list.count());
return aDefault; return aDefault;
} }
@ -270,7 +271,7 @@ QVariant KConfigGroup::convertToQVariant(const char *pKey, const QByteArray &val
const auto list = asRealList(value); const auto list = asRealList(value);
if (list.count() != 2) { if (list.count() != 2) {
qWarning() << errString(pKey, value, aDefault) qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault)
<< formatError(2, list.count()); << formatError(2, list.count());
return aDefault; return aDefault;
} }
@ -280,13 +281,13 @@ QVariant KConfigGroup::convertToQVariant(const char *pKey, const QByteArray &val
const auto list = asIntList(value); const auto list = asIntList(value);
if (list.count() != 4) { if (list.count() != 4) {
qWarning() << errString(pKey, value, aDefault) qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault)
<< formatError(4, list.count()); << formatError(4, list.count());
return aDefault; return aDefault;
} }
const QRect rect(list.at(0), list.at(1), list.at(2), list.at(3)); const QRect rect(list.at(0), list.at(1), list.at(2), list.at(3));
if (!rect.isValid()) { if (!rect.isValid()) {
qWarning() << errString(pKey, value, aDefault); qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault);
return aDefault; return aDefault;
} }
return rect; return rect;
@ -295,13 +296,13 @@ QVariant KConfigGroup::convertToQVariant(const char *pKey, const QByteArray &val
const auto list = asRealList(value); const auto list = asRealList(value);
if (list.count() != 4) { if (list.count() != 4) {
qWarning() << errString(pKey, value, aDefault) qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault)
<< formatError(4, list.count()); << formatError(4, list.count());
return aDefault; return aDefault;
} }
const QRectF rect(list.at(0), list.at(1), list.at(2), list.at(3)); const QRectF rect(list.at(0), list.at(1), list.at(2), list.at(3));
if (!rect.isValid()) { if (!rect.isValid()) {
qWarning() << errString(pKey, value, aDefault); qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault);
return aDefault; return aDefault;
} }
return rect; return rect;
@ -310,13 +311,13 @@ QVariant KConfigGroup::convertToQVariant(const char *pKey, const QByteArray &val
const auto list = asIntList(value); const auto list = asIntList(value);
if (list.count() != 2) { if (list.count() != 2) {
qWarning() << errString(pKey, value, aDefault) qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault)
<< formatError(2, list.count()); << formatError(2, list.count());
return aDefault; return aDefault;
} }
const QSize size(list.at(0), list.at(1)); const QSize size(list.at(0), list.at(1));
if (!size.isValid()) { if (!size.isValid()) {
qWarning() << errString(pKey, value, aDefault); qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault);
return aDefault; return aDefault;
} }
return size; return size;
@ -325,13 +326,13 @@ QVariant KConfigGroup::convertToQVariant(const char *pKey, const QByteArray &val
const auto list = asRealList(value); const auto list = asRealList(value);
if (list.count() != 2) { if (list.count() != 2) {
qWarning() << errString(pKey, value, aDefault) qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault)
<< formatError(2, list.count()); << formatError(2, list.count());
return aDefault; return aDefault;
} }
const QSizeF size(list.at(0), list.at(1)); const QSizeF size(list.at(0), list.at(1));
if (!size.isValid()) { if (!size.isValid()) {
qWarning() << errString(pKey, value, aDefault); qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault);
return aDefault; return aDefault;
} }
return size; return size;
@ -339,7 +340,7 @@ QVariant KConfigGroup::convertToQVariant(const char *pKey, const QByteArray &val
case QMetaType::QDateTime: { case QMetaType::QDateTime: {
const auto list = asIntList(value); const auto list = asIntList(value);
if (list.count() != 6) { if (list.count() != 6) {
qWarning() << errString(pKey, value, aDefault) qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault)
<< formatError(6, list.count()); << formatError(6, list.count());
return aDefault; return aDefault;
} }
@ -347,7 +348,7 @@ QVariant KConfigGroup::convertToQVariant(const char *pKey, const QByteArray &val
const QTime time(list.at(3), list.at(4), list.at(5)); const QTime time(list.at(3), list.at(4), list.at(5));
const QDateTime dt(date, time); const QDateTime dt(date, time);
if (!dt.isValid()) { if (!dt.isValid()) {
qWarning() << errString(pKey, value, aDefault); qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault);
return aDefault; return aDefault;
} }
return dt; return dt;
@ -358,20 +359,20 @@ QVariant KConfigGroup::convertToQVariant(const char *pKey, const QByteArray &val
list = list.mid(0, 3); // don't break config files that stored QDate as QDateTime list = list.mid(0, 3); // don't break config files that stored QDate as QDateTime
} }
if (list.count() != 3) { if (list.count() != 3) {
qWarning() << errString(pKey, value, aDefault) qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault)
<< formatError(3, list.count()); << formatError(3, list.count());
return aDefault; return aDefault;
} }
const QDate date(list.at(0), list.at(1), list.at(2)); const QDate date(list.at(0), list.at(1), list.at(2));
if (!date.isValid()) { if (!date.isValid()) {
qWarning() << errString(pKey, value, aDefault); qCWarning(KCONFIG_CORE_LOG) << errString(pKey, value, aDefault);
return aDefault; return aDefault;
} }
return date; return date;
} }
case QMetaType::QColor: case QMetaType::QColor:
case QMetaType::QFont: case QMetaType::QFont:
qWarning() << "KConfigGroup::readEntry was passed GUI type '" qCWarning(KCONFIG_CORE_LOG) << "KConfigGroup::readEntry was passed GUI type '"
<< aDefault.typeName() << aDefault.typeName()
<< "' but KConfigGui isn't linked! If it is linked to your program, " << "' but KConfigGui isn't linked! If it is linked to your program, "
"this is a platform bug. Please inform the KDE developers"; "this is a platform bug. Please inform the KDE developers";
@ -383,7 +384,7 @@ QVariant KConfigGroup::convertToQVariant(const char *pKey, const QByteArray &val
break; break;
} }
qWarning() << "unhandled type " << aDefault.typeName(); qCWarning(KCONFIG_CORE_LOG) << "unhandled type " << aDefault.typeName();
return QVariant(); return QVariant();
} }
@ -955,7 +956,7 @@ void KConfigGroup::writeEntry(const char *key, const QVariant &value,
break; break;
case QMetaType::QVariantList: case QMetaType::QVariantList:
if (!value.canConvert(QMetaType::QStringList)) 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"; " information will be lost";
Q_FALLTHROUGH(); Q_FALLTHROUGH();
case QMetaType::QStringList: case QMetaType::QStringList:
@ -1065,7 +1066,7 @@ void KConfigGroup::writeEntry(const char *key, const QVariant &value,
case QMetaType::QColor: case QMetaType::QColor:
case QMetaType::QFont: case QMetaType::QFont:
qWarning() << "KConfigGroup::writeEntry was passed GUI type '" qCWarning(KCONFIG_CORE_LOG) << "KConfigGroup::writeEntry was passed GUI type '"
<< value.typeName() << value.typeName()
<< "' but KConfigGui isn't linked! If it is linked to your program, this is a platform bug. " << "' but KConfigGui isn't linked! If it is linked to your program, this is a platform bug. "
"Please inform the KDE developers"; "Please inform the KDE developers";
@ -1074,7 +1075,7 @@ void KConfigGroup::writeEntry(const char *key, const QVariant &value,
data = QUrl(value.toUrl()).toString().toUtf8(); data = QUrl(value.toUrl()).toString().toUtf8();
break; break;
default: 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); writeEntry(key, data, flags);

@ -26,6 +26,7 @@
#include "kconfigbackend_p.h" #include "kconfigbackend_p.h"
#include "bufferfragment_p.h" #include "bufferfragment_p.h"
#include "kconfigdata.h" #include "kconfigdata.h"
#include "kconfig_core_log_settings.h"
#include <qsavefile.h> #include <qsavefile.h>
#include <qlockfile.h> #include <qlockfile.h>
@ -139,7 +140,7 @@ KConfigIniBackend::parseConfig(const QByteArray &currentLocale, KEntryMap &entry
end = start; end = start;
for (;;) { for (;;) {
if (end == line.length()) { 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? // XXX maybe reset the current group here?
goto next_line; goto next_line;
} }
@ -196,7 +197,7 @@ KConfigIniBackend::parseConfig(const QByteArray &currentLocale, KEntryMap &entry
line.trim(); line.trim();
} }
if (aKey.isEmpty()) { if (aKey.isEmpty()) {
qWarning() << warningProlog(file, lineNo) << "Invalid entry (empty key)"; qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, lineNo) << "Invalid entry (empty key)";
continue; continue;
} }
@ -210,7 +211,7 @@ KConfigIniBackend::parseConfig(const QByteArray &currentLocale, KEntryMap &entry
while ((start = aKey.lastIndexOf('[')) >= 0) { while ((start = aKey.lastIndexOf('[')) >= 0) {
int end = aKey.indexOf(']', start); int end = aKey.indexOf(']', start);
if (end < 0) { if (end < 0) {
qWarning() << warningProlog(file, lineNo) qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, lineNo)
<< "Invalid entry (missing ']')"; << "Invalid entry (missing ']')";
goto next_line; goto next_line;
} else if (end > start + 1 && aKey.at(start + 1) == '$') { // found option(s) } else if (end > start + 1 && aKey.at(start + 1) == '$') { // found option(s)
@ -240,7 +241,7 @@ KConfigIniBackend::parseConfig(const QByteArray &currentLocale, KEntryMap &entry
} }
} else { // found a locale } else { // found a locale
if (!locale.isNull()) { if (!locale.isNull()) {
qWarning() << warningProlog(file, lineNo) qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, lineNo)
<< "Invalid entry (second locale!?)"; << "Invalid entry (second locale!?)";
goto next_line; goto next_line;
} }
@ -250,7 +251,7 @@ KConfigIniBackend::parseConfig(const QByteArray &currentLocale, KEntryMap &entry
aKey.truncate(start); aKey.truncate(start);
} }
if (eqpos < 0) { // Do this here after [$d] was checked 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; continue;
} }
printableToString(&aKey, file, lineNo); printableToString(&aKey, file, lineNo);
@ -511,7 +512,7 @@ bool KConfigIniBackend::writeConfig(const QByteArray &locale, KEntryMap &entryMa
return true; return true;
} }
// Couldn't write. Disk full? // Couldn't write. Disk full?
qWarning() << "Couldn't write" << filePath() << ". Disk full?"; qCWarning(KCONFIG_CORE_LOG) << "Couldn't write" << filePath() << ". Disk full?";
return false; return false;
} }
} else { } else {
@ -855,7 +856,7 @@ char KConfigIniBackend::charFromHex(const char *str, const QFile &file, int line
} else { } else {
QByteArray e(str, 2); QByteArray e(str, 2);
e.prepend("\\x"); e.prepend("\\x");
qWarning() << warningProlog(file, line) << "Invalid hex character " << c qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, line) << "Invalid hex character " << c
<< " in \\x<nn>-type escape sequence \"" << e.constData() << "\"."; << " in \\x<nn>-type escape sequence \"" << e.constData() << "\".";
return 'x'; return 'x';
} }
@ -923,7 +924,7 @@ void KConfigIniBackend::printableToString(BufferFragment *aString, const QFile &
break; break;
default: default:
*r = '\\'; *r = '\\';
qWarning() << warningProlog(file, line) qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, line)
<< QStringLiteral("Invalid escape sequence \"\\%1\".").arg(str[i]); << QStringLiteral("Invalid escape sequence \"\\%1\".").arg(str[i]);
} }
} }

@ -20,6 +20,7 @@
#include "kconfigwatcher.h" #include "kconfigwatcher.h"
#include "config-kconfig.h" #include "config-kconfig.h"
#include "kconfig_core_log_settings.h"
#if KCONFIG_USE_DBUS #if KCONFIG_USE_DBUS
#include <QDBusConnection> #include <QDBusConnection>
@ -85,7 +86,7 @@ KConfigWatcher::KConfigWatcher(const KSharedConfig::Ptr &config):
SLOT(onConfigChangeNotification(QHash<QString,QByteArrayList>))); SLOT(onConfigChangeNotification(QHash<QString,QByteArrayList>)));
} }
#else #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 #endif
} }

@ -34,6 +34,7 @@
#include "kconfig_p.h" #include "kconfig_p.h"
#include "kconfiggroup.h" #include "kconfiggroup.h"
#include "kconfigini_p.h" #include "kconfigini_p.h"
#include "kconfig_core_log_settings.h"
class KDesktopFilePrivate : public KConfigPrivate class KDesktopFilePrivate : public KConfigPrivate
{ {
@ -158,7 +159,7 @@ bool KDesktopFile::isAuthorizedDesktopFile(const QString &path)
// Forbid desktop files outside of standard locations if kiosk is set so // Forbid desktop files outside of standard locations if kiosk is set so
if (!KAuthorized::authorize(QStringLiteral("run_desktop_files"))) { 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; return false;
} }
@ -169,7 +170,7 @@ bool KDesktopFile::isAuthorizedDesktopFile(const QString &path)
return true; 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; return false;
} }

Loading…
Cancel
Save