Commit 25491ccb authored by Maximiliano Curia's avatar Maximiliano Curia
Browse files

Use category logging

Summary:
Without this kactivitymanagerd logs way too much information about the
users activities/actions (see the reported Debian bug as an example) by
default. Logging categories can be easily enabled by the developers that
are interested in this information.

This change uses the categories that were already defined in Debug.cpp,
using resources for database and utils related messages, activities for
activities for activities and ksm related, and applications for the
rest.

Debian-BUG: https://bugs.debian.org/897388

Test Plan: It builds

Reviewers: #plasma, lbeltrame, ivan

Reviewed By: #plasma, ivan

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D12656
parent 66c8f9ae
......@@ -35,6 +35,8 @@
#include <mutex>
#include <map>
#include "Debug.h"
namespace Common {
namespace {
......@@ -92,10 +94,10 @@ public:
m_open = m_database.open();
if (!m_open) {
qWarning() << "KActivities: Database is not open: "
<< m_database.connectionName()
<< m_database.databaseName()
<< m_database.lastError();
qCWarning(KAMD_LOG_RESOURCES) << "KActivities: Database is not open: "
<< m_database.connectionName()
<< m_database.databaseName()
<< m_database.lastError();
if (info.openMode == Database::ReadWrite) {
qFatal("KActivities: Opening the database in RW mode should always succeed");
......@@ -105,7 +107,7 @@ public:
~QSqlDatabaseWrapper()
{
qDebug() << "Closing SQL connection: " << m_connectionName;
qCDebug(KAMD_LOG_RESOURCES) << "Closing SQL connection: " << m_connectionName;
}
QSqlDatabase &get()
......@@ -202,9 +204,9 @@ Database::Ptr Database::instance(Source source, OpenMode openMode)
auto walResult = ptr->pragma(QStringLiteral("journal_mode = WAL"));
if (walResult != "wal") {
qWarning() << "KActivities: Database can not be opened in WAL mode. Check the "
"SQLite version (required >3.7.0). And whether your filesystem "
"supports shared memory";
qCWarning(KAMD_LOG_RESOURCES) << "KActivities: Database can not be opened in WAL mode. Check the "
"SQLite version (required >3.7.0). And whether your filesystem "
"supports shared memory";
return nullptr;
}
......@@ -212,7 +214,7 @@ Database::Ptr Database::instance(Source source, OpenMode openMode)
// it reaches 400k, not 4M as is default
ptr->setPragma(QStringLiteral("wal_autocheckpoint = 100"));
qDebug() << "KActivities: Database connection: " << ptr->d->database->connectionName()
qCDebug(KAMD_LOG_RESOURCES) << "KActivities: Database connection: " << ptr->d->database->connectionName()
<< "\n query_only: " << ptr->pragma(QStringLiteral("query_only"))
<< "\n journal_mode: " << ptr->pragma(QStringLiteral("journal_mode"))
<< "\n wal_autocheckpoint: " << ptr->pragma(QStringLiteral("wal_autocheckpoint"))
......@@ -253,7 +255,7 @@ QSqlQuery Database::execQuery(const QString &query, bool ignoreErrors) const
lastExecutedQuery = query;
if (!ignoreErrors && result.lastError().isValid()) {
qWarning() << "SQL: "
qCWarning(KAMD_LOG_RESOURCES) << "SQL: "
<< "\n error: " << result.lastError()
<< "\n query: " << query;
}
......
......@@ -68,7 +68,7 @@ public:
};
#define DATABASE_TRANSACTION(A) \
/* enable this for debugging only: qDebug() << "Location:" << __FILE__ << __LINE__; */ \
/* enable this for debugging only: qCDebug(KAMD_LOG_RESOURCES) << "Location:" << __FILE__ << __LINE__; */ \
Common::Database::Locker lock(A)
private:
......
......@@ -138,7 +138,7 @@ Activities::Private::Private(Activities *parent)
// configuration file is in a big problem and told us there
// are no running activities, and enlists all of them as stopped.
// In that case, we will pretend all of them are running
qWarning() << "The config file enlisted all activities as stopped";
qCWarning(KAMD_LOG_ACTIVITIES) << "The config file enlisted all activities as stopped";
for (const auto &keys: activities.keys()) {
activities[keys] = Activities::Running;
}
......@@ -436,7 +436,7 @@ Activities::Activities(QObject *parent)
// Initializing config
qDebug() << "Config timer connecting...";
qCDebug(KAMD_LOG_ACTIVITIES) << "Config timer connecting...";
d->connect(&d->configSyncTimer, SIGNAL(timeout()),
SLOT(configSync()),
Qt::QueuedConnection);
......
......@@ -237,7 +237,7 @@ bool Application::loadPlugin(const QString &pluginId)
Application::~Application()
{
qDebug() << "Cleaning up...";
qCDebug(KAMD_LOG_APPLICATION) << "Cleaning up...";
// Waiting for the threads to finish
for (const auto thread : s_moduleThreads) {
......
......@@ -55,7 +55,7 @@ Plugin::~Plugin()
KConfigGroup Plugin::config() const
{
if (d->name.isEmpty()) {
qWarning() << "The plugin needs a name in order to have a config section";
qCWarning(KAMD_LOG_APPLICATION) << "The plugin needs a name in order to have a config section";
return KConfigGroup();
}
......@@ -71,7 +71,7 @@ void Plugin::setName(const QString &name)
Q_ASSERT_X(d->name.isEmpty(), "Plugin::setName", "The name can not be set twice");
Q_ASSERT_X(!name.isEmpty(), "Plugin::setName", "The name can not be empty");
qDebug() << "Setting the name of " << (void*)this << " to " << name;
qCDebug(KAMD_LOG_APPLICATION) << "Setting the name of " << (void*)this << " to " << name;
d->name = name;
}
......
......@@ -152,7 +152,7 @@ void KSMServer::Private::process()
void KSMServer::Private::makeRunning(bool value)
{
if (!kwin) {
qDebug() << "Activities KSM: No kwin, marking activity as: " << value;
qCDebug(KAMD_LOG_ACTIVITIES) << "Activities KSM: No kwin, marking activity as: " << value;
subSessionSendEvent(value ? KSMServer::Started : KSMServer::Stopped);
return;
}
......@@ -163,7 +163,7 @@ void KSMServer::Private::makeRunning(bool value)
const auto watcher = new QDBusPendingCallWatcher(call, this);
qDebug() << "Activities KSM: Telling kwin to start/stop activity : " << processingActivity << value;
qCDebug(KAMD_LOG_ACTIVITIES) << "Activities KSM: Telling kwin to start/stop activity : " << processingActivity << value;
QObject::connect(
watcher, SIGNAL(finished(QDBusPendingCallWatcher *)),
this,
......@@ -174,11 +174,11 @@ void KSMServer::Private::makeRunning(bool value)
void KSMServer::Private::startCallFinished(QDBusPendingCallWatcher *call)
{
qDebug() << "Activities KSM: Start call is finished";
qCDebug(KAMD_LOG_ACTIVITIES) << "Activities KSM: Start call is finished";
QDBusPendingReply<bool> reply = *call;
if (reply.isError()) {
qDebug() << "Activities KSM: Error in getting a reply for start, marking as started";
qCDebug(KAMD_LOG_ACTIVITIES) << "Activities KSM: Error in getting a reply for start, marking as started";
subSessionSendEvent(KSMServer::Started);
} else {
......@@ -187,10 +187,10 @@ void KSMServer::Private::startCallFinished(QDBusPendingCallWatcher *call)
const auto retval = reply.argumentAt<0>();
if (!retval) {
qDebug() << "Activities KSM: Error starting, marking as stopped";
qCDebug(KAMD_LOG_ACTIVITIES) << "Activities KSM: Error starting, marking as stopped";
subSessionSendEvent(KSMServer::Stopped);
} else {
qDebug() << "Activities KSM: All OK starting, marking as starting";
qCDebug(KAMD_LOG_ACTIVITIES) << "Activities KSM: All OK starting, marking as starting";
subSessionSendEvent(KSMServer::Started);
}
}
......@@ -200,11 +200,11 @@ void KSMServer::Private::startCallFinished(QDBusPendingCallWatcher *call)
void KSMServer::Private::stopCallFinished(QDBusPendingCallWatcher *call)
{
qDebug() << "Activities KSM: Stop call is finished";
qCDebug(KAMD_LOG_ACTIVITIES) << "Activities KSM: Stop call is finished";
QDBusPendingReply<bool> reply = *call;
if (reply.isError()) {
qDebug() << "Activities KSM: Error in getting a reply for stop, marking as stopped";
qCDebug(KAMD_LOG_ACTIVITIES) << "Activities KSM: Error in getting a reply for stop, marking as stopped";
subSessionSendEvent(KSMServer::Stopped);
} else {
......@@ -213,10 +213,10 @@ void KSMServer::Private::stopCallFinished(QDBusPendingCallWatcher *call)
const auto retval = reply.argumentAt<0>();
if (!retval) {
qDebug() << "Activities KSM: Error stopping, marking as started";
qCDebug(KAMD_LOG_ACTIVITIES) << "Activities KSM: Error stopping, marking as started";
subSessionSendEvent(KSMServer::FailedToStop);
} else {
qDebug() << "Activities KSM: All OK stopping, marking as stopped";
qCDebug(KAMD_LOG_ACTIVITIES) << "Activities KSM: All OK stopping, marking as stopped";
subSessionSendEvent(KSMServer::Stopped);
}
}
......
......@@ -14,6 +14,7 @@ include_directories (
set (
runapplication_SRCS
RunApplicationPlugin.cpp
${KACTIVITIES_CURRENT_ROOT_SOURCE_DIR}/src/service/Debug.cpp
${plugin_implementation_SRCS}
)
......
......@@ -119,10 +119,10 @@ void RunApplicationPlugin::executeIn(const QString &path) const
QString filePath = directory.filePath(item);
KService service(filePath);
if (service.isValid() && service.isApplication()) {
qDebug() << "Starting: " << service.exec();
qCDebug(KAMD_LOG_APPLICATION) << "Starting: " << service.exec();
QProcess::startDetached(service.exec());
} else {
qDebug() << "Openning file: " << QUrl::fromLocalFile(filePath);
qCDebug(KAMD_LOG_APPLICATION) << "Openning file: " << QUrl::fromLocalFile(filePath);
QDesktopServices::openUrl(QUrl::fromLocalFile(filePath));
}
}
......
......@@ -10,6 +10,7 @@ set (
ResourceScoreMaintainer.cpp
ResourceLinking.cpp
${KACTIVITIES_CURRENT_ROOT_SOURCE_DIR}/src/service/Debug.cpp
${KACTIVITIES_CURRENT_ROOT_SOURCE_DIR}/src/common/database/Database.cpp
${KACTIVITIES_CURRENT_ROOT_SOURCE_DIR}/src/common/database/schema/ResourcesDatabaseSchema.cpp
......
......@@ -65,11 +65,11 @@ ResourcesDatabaseMigrator::ResourcesDatabaseMigrator()
= QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)
+ QStringLiteral("/kactivitymanagerd/resources/");
qDebug() << "Creating directory: " << databaseDir;
qCDebug(KAMD_LOG_RESOURCES) << "Creating directory: " << databaseDir;
auto created = QDir().mkpath(databaseDir);
if (!created || !QDir(databaseDir).exists()) {
qWarning() << "Database folder can not be created!";
qCWarning(KAMD_LOG_RESOURCES) << "Database folder can not be created!";
}
d->database = Common::Database::instance(
......
......@@ -65,11 +65,11 @@ void ResourceLinking::LinkResourceToActivity(QString initiatingAgent,
QString targettedResource,
QString usedActivity)
{
qDebug() << "Linking " << targettedResource << " to " << usedActivity << " from " << initiatingAgent;
qCDebug(KAMD_LOG_RESOURCES) << "Linking " << targettedResource << " to " << usedActivity << " from " << initiatingAgent;
if (!validateArguments(initiatingAgent, targettedResource, usedActivity)) {
qWarning() << "Invalid arguments" << initiatingAgent
<< targettedResource << usedActivity;
qCWarning(KAMD_LOG_RESOURCES) << "Invalid arguments" << initiatingAgent
<< targettedResource << usedActivity;
return;
}
......@@ -107,12 +107,12 @@ void ResourceLinking::LinkResourceToActivity(QString initiatingAgent,
);
if (!usedActivity.isEmpty()) {
// qDebug() << "Sending link event added: activities:/" << usedActivity;
// qCDebug(KAMD_LOG_RESOURCES) << "Sending link event added: activities:/" << usedActivity;
org::kde::KDirNotify::emitFilesAdded(QUrl(QStringLiteral("activities:/")
+ usedActivity));
if (usedActivity == StatsPlugin::self()->currentActivity()) {
// qDebug() << "Sending link event added: activities:/current";
// qCDebug(KAMD_LOG_RESOURCES) << "Sending link event added: activities:/current";
org::kde::KDirNotify::emitFilesAdded(
QUrl(QStringLiteral("activities:/current")));
}
......@@ -126,11 +126,11 @@ void ResourceLinking::UnlinkResourceFromActivity(QString initiatingAgent,
QString targettedResource,
QString usedActivity)
{
// qDebug() << "Unlinking " << targettedResource << " from " << usedActivity << " from " << initiatingAgent;
// qCDebug(KAMD_LOG_RESOURCES) << "Unlinking " << targettedResource << " from " << usedActivity << " from " << initiatingAgent;
if (!validateArguments(initiatingAgent, targettedResource, usedActivity)) {
qWarning() << "Invalid arguments" << initiatingAgent
<< targettedResource << usedActivity;
qCWarning(KAMD_LOG_RESOURCES) << "Invalid arguments" << initiatingAgent
<< targettedResource << usedActivity;
return;
}
......@@ -180,12 +180,12 @@ void ResourceLinking::UnlinkResourceFromActivity(QString initiatingAgent,
auto mangled = QString::fromLatin1(targettedResource.toUtf8().toBase64(
QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals));
// qDebug() << "Sending link event removed: activities:/" << usedActivity << '/' << mangled;
// qCDebug(KAMD_LOG_RESOURCES) << "Sending link event removed: activities:/" << usedActivity << '/' << mangled;
org::kde::KDirNotify::emitFilesRemoved(
{ QUrl(QStringLiteral("activities:/") + usedActivity + '/' + mangled) });
if (usedActivity == StatsPlugin::self()->currentActivity()) {
// qDebug() << "Sending link event removed: activities:/current/" << mangled;
// qCDebug(KAMD_LOG_RESOURCES) << "Sending link event removed: activities:/current/" << mangled;
org::kde::KDirNotify::emitFilesRemoved({
QUrl(QStringLiteral("activities:/current/") + mangled) });
}
......@@ -237,7 +237,7 @@ bool ResourceLinking::validateArguments(QString &initiatingAgent,
{
// Validating targetted resource
if (targettedResource.isEmpty()) {
qDebug() << "Resource is invalid -- empty";
qCDebug(KAMD_LOG_RESOURCES) << "Resource is invalid -- empty";
return false;
}
......@@ -249,7 +249,7 @@ bool ResourceLinking::validateArguments(QString &initiatingAgent,
QFileInfo file(targettedResource);
if (!file.exists()) {
qDebug() << "Resource is invalid -- the file does not exist";
qCDebug(KAMD_LOG_RESOURCES) << "Resource is invalid -- the file does not exist";
return false;
}
......@@ -275,13 +275,13 @@ bool ResourceLinking::validateArguments(QString &initiatingAgent,
&& usedActivity != ":global"
&& usedActivity != ":any"
&& !StatsPlugin::self()->listActivities().contains(usedActivity)) {
qDebug() << "Activity is invalid, it does not exist";
qCDebug(KAMD_LOG_RESOURCES) << "Activity is invalid, it does not exist";
return false;
}
// qDebug() << "agent" << initiatingAgent
// << "resource" << targettedResource
// << "activity" << usedActivity;
// qCDebug(KAMD_LOG_RESOURCES) << "agent" << initiatingAgent
// << "resource" << targettedResource
// << "activity" << usedActivity;
return true;
}
......@@ -291,14 +291,14 @@ void ResourceLinking::onActivityAdded(const QString &activity)
Q_UNUSED(activity);
// Notify KIO
// qDebug() << "Added: activities:/ (" << activity << ")";
// qCDebug(KAMD_LOG_RESOURCES) << "Added: activities:/ (" << activity << ")";
org::kde::KDirNotify::emitFilesAdded(QUrl(QStringLiteral("activities:/")));
}
void ResourceLinking::onActivityRemoved(const QString &activity)
{
// Notify KIO
// qDebug() << "Removed: activities:/" << activity;
// qCDebug(KAMD_LOG_RESOURCES) << "Removed: activities:/" << activity;
org::kde::KDirNotify::emitFilesRemoved(
{ QUrl(QStringLiteral("activities:/") + activity) });
......@@ -310,7 +310,7 @@ void ResourceLinking::onCurrentActivityChanged(const QString &activity)
Q_UNUSED(activity);
// Notify KIO
// qDebug() << "Changed: activities:/current -> " << activity;
// qCDebug(KAMD_LOG_RESOURCES) << "Changed: activities:/current -> " << activity;
org::kde::KDirNotify::emitFilesAdded(
{ QUrl(QStringLiteral("activities:/current")) });
}
......@@ -155,7 +155,7 @@ void ResourceScoreCache::update()
DATABASE_TRANSACTION(*resourcesDatabase());
qDebug() << "Creating the cache for: " << d->resource;
qCDebug(KAMD_LOG_RESOURCES) << "Creating the cache for: " << d->resource;
// This can fail if we have the cache already made
auto isCacheNew = Utils::exec(
......@@ -180,9 +180,9 @@ void ResourceScoreCache::update()
lastUpdate.setTime_t(result["lastUpdate"].toUInt());
firstUpdate.setTime_t(result["firstUpdate"].toUInt());
qDebug() << "Already in database? " << (!isCacheNew);
qDebug() << " First update : " << firstUpdate;
qDebug() << " Last update : " << lastUpdate;
qCDebug(KAMD_LOG_RESOURCES) << "Already in database? " << (!isCacheNew);
qCDebug(KAMD_LOG_RESOURCES) << " First update : " << firstUpdate;
qCDebug(KAMD_LOG_RESOURCES) << " Last update : " << lastUpdate;
if (isCacheNew) {
// If we haven't had the cache before, set the score to 0
......@@ -200,10 +200,10 @@ void ResourceScoreCache::update()
// Calculating the updated score
// We are processing all events since the last cache update
qDebug() << "After the adjustment";
qDebug() << " Current score : " << score;
qDebug() << " First update : " << firstUpdate;
qDebug() << " Last update : " << lastUpdate;
qCDebug(KAMD_LOG_RESOURCES) << "After the adjustment";
qCDebug(KAMD_LOG_RESOURCES) << " Current score : " << score;
qCDebug(KAMD_LOG_RESOURCES) << " First update : " << firstUpdate;
qCDebug(KAMD_LOG_RESOURCES) << " Last update : " << lastUpdate;
Utils::exec(Utils::FailOnError, Queries::self().getScoreAdditionQuery,
":usedActivity", d->activity,
......@@ -220,7 +220,7 @@ void ResourceScoreCache::update()
const auto end = result["end"].toUInt();
const auto intervalLength = end - lastEventStart;
qDebug() << "Interval length is " << intervalLength;
qCDebug(KAMD_LOG_RESOURCES) << "Interval length is " << intervalLength;
if (intervalLength == 0) {
// We have an Accessed event - otherwise, this wouldn't be 0
......@@ -232,7 +232,7 @@ void ResourceScoreCache::update()
}
}
qDebug() << " New score : " << score;
qCDebug(KAMD_LOG_RESOURCES) << " New score : " << score;
// Updating the score
......@@ -245,10 +245,10 @@ void ResourceScoreCache::update()
);
// Notifying the world
qDebug() << "ResourceScoreUpdated:"
<< d->activity
<< d->application
<< d->resource
qCDebug(KAMD_LOG_RESOURCES) << "ResourceScoreUpdated:"
<< d->activity
<< d->application
<< d->resource
;
emit QMetaObject::invokeMethod(StatsPlugin::self(),
"ResourceScoreUpdated",
......
......@@ -61,8 +61,8 @@ namespace Utils {
if (eh == FailOnError) {
if ((!success) && (errorCount++ < 2)) {
qDebug() << query.lastQuery();
qDebug() << query.lastError();
qCDebug(KAMD_LOG_RESOURCES) << query.lastQuery();
qCDebug(KAMD_LOG_RESOURCES) << query.lastError();
}
Q_ASSERT_X(success, "Uils::exec", "Query failed");
}
......
......@@ -40,7 +40,7 @@ namespace detail { //_
inline void test_continuation(const QJSValue &continuation)
{
if (!continuation.isCallable()) {
qWarning() << "Passed handler is not callable: " << continuation.toString();
qCWarning(KAMD_LOG_RESOURCES) << "Passed handler is not callable: " << continuation.toString();
}
}
......@@ -50,7 +50,7 @@ namespace detail { //_
{
auto result = continuation.call({ future.result() });
if (result.isError()) {
qWarning() << "Handler returned this error: " << result.toString();
qCWarning(KAMD_LOG_RESOURCES) << "Handler returned this error: " << result.toString();
}
}
......@@ -59,7 +59,7 @@ namespace detail { //_
Q_UNUSED(future);
auto result = continuation.call({});
if (result.isError()) {
qWarning() << "Handler returned this error: " << result.toString();
qCWarning(KAMD_LOG_RESOURCES) << "Handler returned this error: " << result.toString();
}
}
#endif
......
......@@ -29,7 +29,7 @@ void DBusCallFutureInterface<void>::callFinished()
{
deleteLater();
// qDebug() << "This is call end";
// qCDebug(KAMD_LOG_RESOURCES) << "This is call end";
this->reportFinished();
}
......
......@@ -31,7 +31,7 @@ namespace utils {
template<typename T>
T debug_and_return(const char * message, T && value) {
#ifdef QT_DEBUG
qDebug() << message << " " << value;
qCDebug(KAMD_LOG_RESOURCES) << message << " " << value;
#endif
return std::forward<T>(value);
......@@ -41,7 +41,7 @@ template<typename T>
T debug_and_return(bool debug, const char * message, T && value) {
#ifdef QT_DEBUG
if (debug) {
qDebug() << message << " " << value;
qCDebug(KAMD_LOG_RESOURCES) << message << " " << value;
}
#endif
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment