From da2b049e248c1ad7efeb53685158a205335e4e36 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 7 Jul 2016 22:23:49 +0200 Subject: A new debug system. Instead of a single #define as debug area the new system allows for an identifier for each debug message with the structure component.area. The component is a dot separated identifier of the runtime component, such as the process or the plugin. The area is the code component, and can be as such defined at compiletime. The idea of this system is that it becomes possible to i.e. look at the output of all messages in the query subsystem of a specific resource (something that happens in the client process, but in the resource-specific subcomponent). The new macros are supposed to be less likely to clash with other names, hence the new names. --- examples/dummyresource/resourcefactory.cpp | 12 +-- examples/imapresource/imapresource.cpp | 99 +++++++++++----------- examples/imapresource/imapserverproxy.cpp | 40 ++++----- .../imapresource/tests/imapserverproxytest.cpp | 10 ++- examples/maildirresource/facade.cpp | 4 +- examples/maildirresource/maildirresource.cpp | 57 ++++++------- .../mailtransportresource.cpp | 18 ++-- 7 files changed, 123 insertions(+), 117 deletions(-) (limited to 'examples') diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp index 21a76ad..0f7463f 100644 --- a/examples/dummyresource/resourcefactory.cpp +++ b/examples/dummyresource/resourcefactory.cpp @@ -48,6 +48,8 @@ #define ENTITY_TYPE_MAIL "mail" #define ENTITY_TYPE_FOLDER "folder" +SINK_DEBUG_AREA("dummyresource") + class DummySynchronizer : public Sink::Synchronizer { public: @@ -105,12 +107,12 @@ class DummySynchronizer : public Sink::Synchronizer { auto entity = createEntity(remoteId, it.value()); createOrModify(bufferType, remoteId, *entity); } - Trace() << "Sync of " << count << " entities of type " << bufferType << " done." << Sink::Log::TraceTime(time->elapsed()); + SinkTrace() << "Sync of " << count << " entities of type " << bufferType << " done." << Sink::Log::TraceTime(time->elapsed()); } KAsync::Job synchronizeWithSource() Q_DECL_OVERRIDE { - Log() << " Synchronizing with the source"; + SinkLog() << " Synchronizing with the source"; return KAsync::start([this]() { synchronize(ENTITY_TYPE_EVENT, DummyStore::instance().events(), [this](const QByteArray &ridBuffer, const QMap &data) { return createEvent(ridBuffer, data); @@ -121,7 +123,7 @@ class DummySynchronizer : public Sink::Synchronizer { synchronize(ENTITY_TYPE_FOLDER, DummyStore::instance().folders(), [this](const QByteArray &ridBuffer, const QMap &data) { return createFolder(ridBuffer, data); }); - Log() << "Done Synchronizing"; + SinkLog() << "Done Synchronizing"; }); } @@ -147,7 +149,7 @@ DummyResource::~DummyResource() KAsync::Job DummyResource::synchronizeWithSource() { - Trace() << "Synchronize with source and sending a notification about it"; + SinkTrace() << "Synchronize with source and sending a notification about it"; Sink::Notification n; n.id = "connected"; n.type = Sink::Notification::Status; @@ -160,7 +162,7 @@ KAsync::Job DummyResource::synchronizeWithSource() KAsync::Job DummyResource::inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) { - Trace() << "Inspecting " << inspectionType << domainType << entityId << property << expectedValue; + SinkTrace() << "Inspecting " << inspectionType << domainType << entityId << property << expectedValue; if (property == "testInspection") { if (expectedValue.toBool()) { //Success diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp index e23add8..92f64bf 100644 --- a/examples/imapresource/imapresource.cpp +++ b/examples/imapresource/imapresource.cpp @@ -54,8 +54,7 @@ #define ENTITY_TYPE_MAIL "mail" #define ENTITY_TYPE_FOLDER "folder" -#undef DEBUG_AREA -#define DEBUG_AREA "resource.imap" +SINK_DEBUG_AREA("imapresource") using namespace Imap; using namespace Sink; @@ -95,7 +94,7 @@ public: QByteArray createFolder(const QString &folderName, const QString &folderPath, const QString &parentFolderRid, const QByteArray &icon) { - Trace() << "Creating folder: " << folderName << parentFolderRid; + SinkTrace() << "Creating folder: " << folderName << parentFolderRid; const auto remoteId = folderPath.toUtf8(); const auto bufferType = ENTITY_TYPE_FOLDER; Sink::ApplicationDomain::Folder folder; @@ -118,7 +117,7 @@ public: void synchronizeFolders(const QVector &folderList) { const QByteArray bufferType = ENTITY_TYPE_FOLDER; - Trace() << "Found folders " << folderList.size(); + SinkTrace() << "Found folders " << folderList.size(); scanForRemovals(bufferType, [this, &bufferType](const std::function &callback) { @@ -154,7 +153,7 @@ public: time->start(); const QByteArray bufferType = ENTITY_TYPE_MAIL; - Trace() << "Importing new mail." << path; + SinkTrace() << "Importing new mail." << path; const auto folderLocalId = syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, path.toUtf8()); @@ -163,7 +162,7 @@ public: count++; const auto remoteId = assembleMailRid(folderLocalId, message.uid); - Trace() << "Found a mail " << remoteId << message.msg->subject(true)->asUnicodeString() << message.flags; + SinkTrace() << "Found a mail " << remoteId << message.msg->subject(true)->asUnicodeString() << message.flags; auto mail = Sink::ApplicationDomain::Mail::create(mResourceInstanceIdentifier); mail.setFolder(folderLocalId); @@ -174,7 +173,7 @@ public: createOrModify(bufferType, remoteId, mail); } const auto elapsed = time->elapsed(); - Log() << "Synchronized " << count << " mails in " << path << Sink::Log::TraceTime(elapsed) << " " << elapsed/qMax(count, 1) << " [ms/mail]"; + SinkLog() << "Synchronized " << count << " mails in " << path << Sink::Log::TraceTime(elapsed) << " " << elapsed/qMax(count, 1) << " [ms/mail]"; } void synchronizeRemovals(const QString &path, const QSet &messages) @@ -183,7 +182,7 @@ public: time->start(); const QByteArray bufferType = ENTITY_TYPE_MAIL; - Trace() << "Finding removed mail."; + SinkTrace() << "Finding removed mail."; const auto folderLocalId = syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, path.toUtf8()); @@ -196,7 +195,7 @@ public: callback(sinkId); }, [&](const Index::Error &error) { - Warning() << "Error in index: " << error.message << property; + SinkWarning() << "Error in index: " << error.message << property; }); }, [messages, path, &count](const QByteArray &remoteId) -> bool { @@ -209,24 +208,24 @@ public: ); const auto elapsed = time->elapsed(); - Log() << "Removed " << count << " mails in " << path << Sink::Log::TraceTime(elapsed) << " " << elapsed/qMax(count, 1) << " [ms/mail]"; + SinkLog() << "Removed " << count << " mails in " << path << Sink::Log::TraceTime(elapsed) << " " << elapsed/qMax(count, 1) << " [ms/mail]"; } KAsync::Job synchronizeWithSource() Q_DECL_OVERRIDE { - Log() << " Synchronizing"; + SinkLog() << " Synchronizing"; return KAsync::start([this](KAsync::Future future) { - Trace() << "Connecting to:" << mServer << mPort; - Trace() << "as:" << mUser; + SinkTrace() << "Connecting to:" << mServer << mPort; + SinkTrace() << "as:" << mUser; ImapServerProxy imap(mServer, mPort); auto loginFuture = imap.login(mUser, mPassword).exec(); loginFuture.waitForFinished(); if (loginFuture.errorCode()) { - Warning() << "Login failed."; + SinkWarning() << "Login failed."; future.setError(1, "Login failed"); return; } else { - Trace() << "Login was successful"; + SinkTrace() << "Login was successful"; } QVector folderList; @@ -238,11 +237,11 @@ public: }).exec(); folderFuture.waitForFinished(); if (folderFuture.errorCode()) { - Warning() << "Folder sync failed."; + SinkWarning() << "Folder sync failed."; future.setError(1, "Folder list sync failed"); return; } else { - Trace() << "Folder sync was successful"; + SinkTrace() << "Folder sync was successful"; } for (const auto &folder : folderList) { @@ -251,7 +250,7 @@ public: } QSet uids; auto messagesFuture = imap.fetchMessages(folder, [this, folder, &uids](const QVector &messages) { - Trace() << "Synchronizing mails" << folder.normalizedPath(); + SinkTrace() << "Synchronizing mails" << folder.normalizedPath(); for (const auto &msg : messages) { uids << msg.uid; } @@ -260,16 +259,16 @@ public: messagesFuture.waitForFinished(); commit(); if (messagesFuture.errorCode()) { - Warning() << "Folder sync failed: " << folder.normalizedPath(); + SinkWarning() << "Folder sync failed: " << folder.normalizedPath(); continue; } //Remove what there is to remove synchronizeRemovals(folder.normalizedPath(), uids); commit(); - Trace() << "Folder synchronized: " << folder.normalizedPath(); + SinkTrace() << "Folder synchronized: " << folder.normalizedPath(); } - Log() << "Done Synchronizing"; + SinkLog() << "Done Synchronizing"; future.setFinished(); }); } @@ -310,7 +309,7 @@ public: .then([imap, mailbox, rid, mail](qint64 uid) { const auto remoteId = assembleMailRid(mail, uid); //FIXME this get's called after the final error handler? WTF? - Trace() << "Finished creating a new mail: " << remoteId; + SinkTrace() << "Finished creating a new mail: " << remoteId; *rid = remoteId; }).then([rid, imap]() { //FIXME fix KJob so we don't need this extra clause return *rid; @@ -319,19 +318,19 @@ public: const auto folderId = folderIdFromMailRid(oldRemoteId); const QString mailbox = syncStore().resolveLocalId(ENTITY_TYPE_FOLDER, folderId); const auto uid = uidFromMailRid(oldRemoteId); - Trace() << "Removing a mail: " << oldRemoteId << "in the mailbox: " << mailbox; + SinkTrace() << "Removing a mail: " << oldRemoteId << "in the mailbox: " << mailbox; KIMAP::ImapSet set; set.add(uid); return login.then(imap->remove(mailbox, set)) .then([imap, oldRemoteId]() { - Trace() << "Finished removing a mail: " << oldRemoteId; + SinkTrace() << "Finished removing a mail: " << oldRemoteId; return QByteArray(); }); } else if (operation == Sink::Operation_Modification) { const QString mailbox = syncStore().resolveLocalId(ENTITY_TYPE_FOLDER, mail.getFolder()); const auto uid = uidFromMailRid(oldRemoteId); - Trace() << "Modifying a mail: " << oldRemoteId << " in the mailbox: " << mailbox << changedProperties; + SinkTrace() << "Modifying a mail: " << oldRemoteId << " in the mailbox: " << mailbox << changedProperties; QByteArrayList flags; if (!mail.getUnread()) { @@ -344,7 +343,7 @@ public: const bool messageMoved = changedProperties.contains(ApplicationDomain::Mail::Folder::name); const bool messageChanged = changedProperties.contains(ApplicationDomain::Mail::MimeMessage::name); if (messageChanged || messageMoved) { - Trace() << "Replacing message."; + SinkTrace() << "Replacing message."; const auto folderId = folderIdFromMailRid(oldRemoteId); const QString oldMailbox = syncStore().resolveLocalId(ENTITY_TYPE_FOLDER, folderId); QByteArray content = KMime::LFtoCRLF(mail.getMimeMessage()); @@ -355,7 +354,7 @@ public: return login.then(imap->append(mailbox, content, flags, internalDate)) .then([imap, mailbox, rid, mail](qint64 uid) { const auto remoteId = assembleMailRid(mail, uid); - Trace() << "Finished creating a modified mail: " << remoteId; + SinkTrace() << "Finished creating a modified mail: " << remoteId; *rid = remoteId; }) .then(imap->remove(oldMailbox, set)) @@ -363,13 +362,13 @@ public: return *rid; }); } else { - Trace() << "Updating flags only."; + SinkTrace() << "Updating flags only."; KIMAP::ImapSet set; set.add(uid); return login.then(imap->select(mailbox)) .then(imap->storeFlags(set, flags)) .then([imap, mailbox]() { - Trace() << "Finished modifying mail"; + SinkTrace() << "Finished modifying mail"; }) .then([oldRemoteId, imap]() { return oldRemoteId; @@ -388,11 +387,11 @@ public: if (!folder.getParent().isEmpty()) { parentFolder = syncStore().resolveLocalId(ENTITY_TYPE_FOLDER, folder.getParent()); } - Trace() << "Creating a new folder: " << parentFolder << folder.getName(); + SinkTrace() << "Creating a new folder: " << parentFolder << folder.getName(); auto rid = QSharedPointer::create(); auto createFolder = login.then(imap->createSubfolder(parentFolder, folder.getName())) .then([imap, rid](const QString &createdFolder) { - Trace() << "Finished creating a new folder: " << createdFolder; + SinkTrace() << "Finished creating a new folder: " << createdFolder; *rid = createdFolder.toUtf8(); }); if (folder.getSpecialPurpose().isEmpty()) { @@ -414,15 +413,15 @@ public: for (const auto &purpose : folder.getSpecialPurpose()) { if (specialPurposeFolders->contains(purpose)) { auto f = specialPurposeFolders->value(purpose); - Trace() << "Merging specialpurpose folder with: " << f << " with purpose: " << purpose; + SinkTrace() << "Merging specialpurpose folder with: " << f << " with purpose: " << purpose; *rid = f.toUtf8(); return KAsync::null(); } } - Trace() << "No match found for merging, creating a new folder"; + SinkTrace() << "No match found for merging, creating a new folder"; return imap->createSubfolder(parentFolder, folder.getName()) .then([imap, rid](const QString &createdFolder) { - Trace() << "Finished creating a new folder: " << createdFolder; + SinkTrace() << "Finished creating a new folder: " << createdFolder; *rid = createdFolder.toUtf8(); }); @@ -433,18 +432,18 @@ public: return mergeJob; } } else if (operation == Sink::Operation_Removal) { - Trace() << "Removing a folder: " << oldRemoteId; + SinkTrace() << "Removing a folder: " << oldRemoteId; return login.then(imap->remove(oldRemoteId)) .then([oldRemoteId, imap]() { - Trace() << "Finished removing a folder: " << oldRemoteId; + SinkTrace() << "Finished removing a folder: " << oldRemoteId; return QByteArray(); }); } else if (operation == Sink::Operation_Modification) { - Trace() << "Renaming a folder: " << oldRemoteId << folder.getName(); + SinkTrace() << "Renaming a folder: " << oldRemoteId << folder.getName(); auto rid = QSharedPointer::create(); return login.then(imap->renameSubfolder(oldRemoteId, folder.getName())) .then([imap, rid](const QString &createdFolder) { - Trace() << "Finished renaming a folder: " << createdFolder; + SinkTrace() << "Finished renaming a folder: " << createdFolder; *rid = createdFolder.toUtf8(); }) .then([rid](){ @@ -515,7 +514,7 @@ KAsync::Job ImapResource::inspect(int inspectionType, const QByteArray &in auto entityStore = QSharedPointer::create(mResourceType, mResourceInstanceIdentifier, transaction); auto syncStore = QSharedPointer::create(synchronizationTransaction); - Trace() << "Inspecting " << inspectionType << domainType << entityId << property << expectedValue; + SinkTrace() << "Inspecting " << inspectionType << domainType << entityId << property << expectedValue; if (domainType == ENTITY_TYPE_MAIL) { const auto mail = entityStore->read(entityId); @@ -523,11 +522,11 @@ KAsync::Job ImapResource::inspect(int inspectionType, const QByteArray &in const auto folderRemoteId = syncStore->resolveLocalId(ENTITY_TYPE_FOLDER, mail.getFolder()); const auto mailRemoteId = syncStore->resolveLocalId(ENTITY_TYPE_MAIL, mail.identifier()); if (mailRemoteId.isEmpty() || folderRemoteId.isEmpty()) { - Warning() << "Missing remote id for folder or mail. " << mailRemoteId << folderRemoteId; + SinkWarning() << "Missing remote id for folder or mail. " << mailRemoteId << folderRemoteId; return KAsync::error(); } const auto uid = uidFromMailRid(mailRemoteId); - Trace() << "Mail remote id: " << folderRemoteId << mailRemoteId << mail.identifier() << folder.identifier(); + SinkTrace() << "Mail remote id: " << folderRemoteId << mailRemoteId << mail.identifier() << folder.identifier(); KIMAP::ImapSet set; set.add(uid); @@ -538,8 +537,8 @@ KAsync::Job ImapResource::inspect(int inspectionType, const QByteArray &in scope.mode = KIMAP::FetchJob::FetchScope::Full; auto imap = QSharedPointer::create(mServer, mPort); auto messageByUid = QSharedPointer>::create(); - Trace() << "Connecting to:" << mServer << mPort; - Trace() << "as:" << mUser; + SinkTrace() << "Connecting to:" << mServer << mPort; + SinkTrace() << "as:" << mUser; auto inspectionJob = imap->login(mUser, mPassword) .then(imap->select(folderRemoteId)) .then(imap->fetch(set, scope, [imap, messageByUid](const QVector &messages) { @@ -574,8 +573,8 @@ KAsync::Job ImapResource::inspect(int inspectionType, const QByteArray &in if (inspectionType == Sink::ResourceControl::Inspection::ExistenceInspectionType) { return inspectionJob.then>([=]() { if (!messageByUid->contains(uid)) { - Warning() << "Existing messages are: " << messageByUid->keys(); - Warning() << "We're looking for: " << uid; + SinkWarning() << "Existing messages are: " << messageByUid->keys(); + SinkWarning() << "We're looking for: " << uid; return KAsync::error(1, "Couldn't find message: " + mailRemoteId); } return KAsync::null(); @@ -587,7 +586,7 @@ KAsync::Job ImapResource::inspect(int inspectionType, const QByteArray &in const auto folder = entityStore->read(entityId); if (inspectionType == Sink::ResourceControl::Inspection::CacheIntegrityInspectionType) { - Log() << "Inspecting cache integrity" << remoteId; + SinkLog() << "Inspecting cache integrity" << remoteId; int expectedCount = 0; Index index("mail.index.folder", transaction); @@ -595,7 +594,7 @@ KAsync::Job ImapResource::inspect(int inspectionType, const QByteArray &in expectedCount++; }, [&](const Index::Error &error) { - Warning() << "Error in index: " << error.message << property; + SinkWarning() << "Error in index: " << error.message << property; }); auto set = KIMAP::ImapSet::fromImapSequenceSet("1:*"); @@ -630,10 +629,10 @@ KAsync::Job ImapResource::inspect(int inspectionType, const QByteArray &in *folderByName << f.pathParts.last(); } })) - .then>([folderByName, folderByPath, folder, remoteId, imap]() { + .then>([this, folderByName, folderByPath, folder, remoteId, imap]() { if (!folderByName->contains(folder.getName())) { - Warning() << "Existing folders are: " << *folderByPath; - Warning() << "We're looking for: " << folder.getName(); + SinkWarning() << "Existing folders are: " << *folderByPath; + SinkWarning() << "We're looking for: " << folder.getName(); return KAsync::error(1, "Wrong folder name: " + remoteId); } return KAsync::null(); diff --git a/examples/imapresource/imapserverproxy.cpp b/examples/imapresource/imapserverproxy.cpp index 1b0a2ec..73ec654 100644 --- a/examples/imapresource/imapserverproxy.cpp +++ b/examples/imapresource/imapserverproxy.cpp @@ -37,6 +37,8 @@ #include "log.h" +SINK_DEBUG_AREA("imapserverproxy") + using namespace Imap; const char* Imap::Flags::Seen = "\\Seen"; @@ -54,16 +56,16 @@ static KAsync::Job runJob(KJob *job, const std::function &f) { return KAsync::start([job, f](KAsync::Future &future) { QObject::connect(job, &KJob::result, [&future, f](KJob *job) { - Trace() << "Job done: " << job->metaObject()->className(); + SinkTrace() << "Job done: " << job->metaObject()->className(); if (job->error()) { - Warning() << "Job failed: " << job->errorString(); + SinkWarning() << "Job failed: " << job->errorString(); future.setError(job->error(), job->errorString()); } else { future.setValue(f(job)); future.setFinished(); } }); - Trace() << "Starting job: " << job->metaObject()->className(); + SinkTrace() << "Starting job: " << job->metaObject()->className(); job->start(); }); } @@ -72,15 +74,15 @@ static KAsync::Job runJob(KJob *job) { return KAsync::start([job](KAsync::Future &future) { QObject::connect(job, &KJob::result, [&future](KJob *job) { - Trace() << "Job done: " << job->metaObject()->className(); + SinkTrace() << "Job done: " << job->metaObject()->className(); if (job->error()) { - Warning() << "Job failed: " << job->errorString(); + SinkWarning() << "Job failed: " << job->errorString(); future.setError(job->error(), job->errorString()); } else { future.setFinished(); } }); - Trace() << "Starting job: " << job->metaObject()->className(); + SinkTrace() << "Starting job: " << job->metaObject()->className(); job->start(); }); } @@ -117,11 +119,11 @@ KAsync::Job ImapServerProxy::login(const QString &username, const QString auto namespaceJob = new KIMAP::NamespaceJob(mSession); return runJob(loginJob).then(runJob(capabilitiesJob)).then([this](){ - Trace() << "Supported capabilities: " << mCapabilities; + SinkTrace() << "Supported capabilities: " << mCapabilities; QStringList requiredExtensions = QStringList() << "UIDPLUS" << "NAMESPACE"; for (const auto &requiredExtension : requiredExtensions) { if (!mCapabilities.contains(requiredExtension)) { - Warning() << "Server doesn't support required capability: " << requiredExtension; + SinkWarning() << "Server doesn't support required capability: " << requiredExtension; //TODO fail the job } } @@ -138,9 +140,9 @@ KAsync::Job ImapServerProxy::login(const QString &username, const QString mUserNamespaces << ns.name; mUserNamespaceSeparator = ns.separator; } - Trace() << "Found personal namespaces: " << mPersonalNamespaces << mPersonalNamespaceSeparator; - Trace() << "Found shared namespaces: " << mSharedNamespaces << mSharedNamespaceSeparator; - Trace() << "Found user namespaces: " << mUserNamespaces << mUserNamespaceSeparator; + SinkTrace() << "Found personal namespaces: " << mPersonalNamespaces << mPersonalNamespaceSeparator; + SinkTrace() << "Found shared namespaces: " << mSharedNamespaces << mSharedNamespaceSeparator; + SinkTrace() << "Found user namespaces: " << mUserNamespaces << mUserNamespaceSeparator; }); } @@ -291,8 +293,8 @@ KAsync::Job> ImapServerProxy::fetchHeaders(const QString &mailbox) const QMap &attrs, const QMap &flags, const QMap &messages) { - Trace() << "Received " << uids.size() << " headers from " << mailbox; - Trace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size(); + SinkTrace() << "Received " << uids.size() << " headers from " << mailbox; + SinkTrace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size(); //TODO based on the data available here, figure out which messages to actually fetch //(we only fetched headers and structure so far) @@ -344,7 +346,7 @@ KAsync::Job ImapServerProxy::createSubfolder(const QString &parentMailb } else { *folder = parentMailbox + mPersonalNamespaceSeparator + folderName; } - Trace() << "Creating subfolder: " << *folder; + SinkTrace() << "Creating subfolder: " << *folder; return create(*folder); }) .then([=]() { @@ -360,7 +362,7 @@ KAsync::Job ImapServerProxy::renameSubfolder(const QString &oldMailbox, auto parts = oldMailbox.split(mPersonalNamespaceSeparator); parts.removeLast(); *folder = parts.join(mPersonalNamespaceSeparator) + mPersonalNamespaceSeparator + newName; - Trace() << "Renaming subfolder: " << oldMailbox << *folder; + SinkTrace() << "Renaming subfolder: " << oldMailbox << *folder; return rename(oldMailbox, *folder); }) .then([=]() { @@ -370,14 +372,14 @@ KAsync::Job ImapServerProxy::renameSubfolder(const QString &oldMailbox, KAsync::Job ImapServerProxy::fetchFolders(std::function &)> callback) { - Trace() << "Fetching folders"; + SinkTrace() << "Fetching folders"; return list(KIMAP::ListJob::IncludeUnsubscribed, [callback](const QList &mailboxes, const QList > &flags){ QVector list; for (int i = 0; i < mailboxes.size(); i++) { const auto mailbox = mailboxes[i]; const auto mailboxFlags = flags[i]; bool noselect = mailboxFlags.contains(QByteArray(FolderFlags::Noselect).toLower()) || mailboxFlags.contains(QByteArray(FolderFlags::Noselect)); - Log() << "Found mailbox: " << mailbox.name << mailboxFlags << FolderFlags::Noselect << noselect; + SinkLog() << "Found mailbox: " << mailbox.name << mailboxFlags << FolderFlags::Noselect << noselect; list << Folder{mailbox.name.split(mailbox.separator), mailbox.name, mailbox.separator, noselect}; } callback(list); @@ -395,9 +397,9 @@ KAsync::Job ImapServerProxy::fetchMessages(const Folder &folder, std::func Q_ASSERT(!mPersonalNamespaceSeparator.isNull()); return select(mailboxFromFolder(folder)).then>([this, callback, folder]() -> KAsync::Job { return fetchHeaders(mailboxFromFolder(folder)).then, QList>([this, callback](const QList &uidsToFetch){ - Trace() << "Uids to fetch: " << uidsToFetch; + SinkTrace() << "Uids to fetch: " << uidsToFetch; if (uidsToFetch.isEmpty()) { - Trace() << "Nothing to fetch"; + SinkTrace() << "Nothing to fetch"; callback(QVector()); return KAsync::null(); } diff --git a/examples/imapresource/tests/imapserverproxytest.cpp b/examples/imapresource/tests/imapserverproxytest.cpp index 6819685..d9af453 100644 --- a/examples/imapresource/tests/imapserverproxytest.cpp +++ b/examples/imapresource/tests/imapserverproxytest.cpp @@ -12,6 +12,8 @@ using namespace Imap; +SINK_DEBUG_AREA("imapserverproxytest") + /** */ class ImapServerProxyTest : public QObject @@ -81,8 +83,8 @@ private slots: const QMap &attrs, const QMap &flags, const QMap &messages) { - Trace() << "Received " << uids.size() << " messages from " << mailbox; - Trace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size(); + SinkTrace() << "Received " << uids.size() << " messages from " << mailbox; + SinkTrace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size(); count += uids.size(); })); @@ -106,8 +108,8 @@ private slots: const QMap &attrs, const QMap &flags, const QMap &messages) { - Trace() << "Received " << uids.size() << " messages from " << mailbox; - Trace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size(); + SinkTrace() << "Received " << uids.size() << " messages from " << mailbox; + SinkTrace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size(); count += uids.size(); })); diff --git a/examples/maildirresource/facade.cpp b/examples/maildirresource/facade.cpp index d8fc02d..256b255 100644 --- a/examples/maildirresource/facade.cpp +++ b/examples/maildirresource/facade.cpp @@ -38,11 +38,11 @@ MaildirResourceMailFacade::MaildirResourceMailFacade(const QByteArray &instanceI const auto folderPath = parts.join('/'); const auto path = folderPath + "/cur/"; - Trace() << "Looking for mail in: " << path << key; + SinkTrace_("", "maildirfacade") << "Looking for mail in: " << path << key; QDir dir(path); const QFileInfoList list = dir.entryInfoList(QStringList() << (key+"*"), QDir::Files); if (list.size() != 1) { - Warning() << "Failed to find message " << path << key << list.size(); + SinkWarning_("", "maildirfacade") << "Failed to find message " << path << key << list.size(); value.setProperty("mimeMessage", QVariant()); } else { value.setProperty("mimeMessage", list.at(0).filePath()); diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp index e1fcfdf..d7a6fff 100644 --- a/examples/maildirresource/maildirresource.cpp +++ b/examples/maildirresource/maildirresource.cpp @@ -51,8 +51,7 @@ #define ENTITY_TYPE_MAIL "mail" #define ENTITY_TYPE_FOLDER "folder" -#undef DEBUG_AREA -#define DEBUG_AREA "resource.maildir" +SINK_DEBUG_AREA("maildirresource") using namespace Sink; @@ -65,8 +64,8 @@ static QString getFilePathFromMimeMessagePath(const QString &mimeMessagePath) QDir dir(path); const QFileInfoList list = dir.entryInfoList(QStringList() << (key+"*"), QDir::Files); if (list.size() != 1) { - Warning() << "Failed to find message " << mimeMessagePath; - Warning() << "Failed to find message " << path; + SinkWarning() << "Failed to find message " << mimeMessagePath; + SinkWarning() << "Failed to find message " << path; return QString(); } return list.first().filePath(); @@ -115,7 +114,7 @@ public: const auto path = getPath(folder, transaction); KPIM::Maildir maildir(path, false); if (!maildir.isValid(true)) { - Warning() << "Maildir is not existing: " << path; + SinkWarning() << "Maildir is not existing: " << path; } auto identifier = maildir.addEntryFromPath(oldPath); return path + "/" + identifier; @@ -124,7 +123,7 @@ public: const auto path = getPath(folder, transaction); KPIM::Maildir maildir(path, false); if (!maildir.isValid(true)) { - Warning() << "Maildir is not existing: " << path; + SinkWarning() << "Maildir is not existing: " << path; } auto oldIdentifier = KPIM::Maildir::getKeyFromFile(oldPath); auto pathParts = oldPath.split('/'); @@ -135,7 +134,7 @@ public: } KPIM::Maildir oldMaildir(oldDirectory, false); if (!oldMaildir.isValid(false)) { - Warning() << "Maildir is not existing: " << path; + SinkWarning() << "Maildir is not existing: " << path; } auto identifier = oldMaildir.moveEntryTo(oldIdentifier, maildir); return path + "/" + identifier; @@ -158,7 +157,7 @@ public: const bool mimeMessageChanged = mimeMessage.isValid() && mimeMessage.toString() != oldEntity.getProperty("mimeMessage").toString(); const bool folderChanged = newFolder.isValid() && newFolder.toString() != oldEntity.getProperty("mimeMessage").toString(); if (mimeMessageChanged || folderChanged) { - Trace() << "Moving mime message: " << mimeMessageChanged << folderChanged; + SinkTrace() << "Moving mime message: " << mimeMessageChanged << folderChanged; auto newPath = moveMessage(mimeMessage.toString(), newEntity.getProperty("folder").toByteArray(), transaction); if (newPath != oldEntity.getProperty("mimeMessage").toString()) { const auto oldPath = getFilePathFromMimeMessagePath(oldEntity.getProperty("mimeMessage").toString()); @@ -278,7 +277,7 @@ public: { const QByteArray bufferType = ENTITY_TYPE_FOLDER; QStringList folderList = listAvailableFolders(); - Trace() << "Found folders " << folderList; + SinkTrace() << "Found folders " << folderList; scanForRemovals(bufferType, [this, &bufferType](const std::function &callback) { @@ -304,23 +303,23 @@ public: void synchronizeMails(const QString &path) { - Trace() << "Synchronizing mails" << path; + SinkTrace() << "Synchronizing mails" << path; auto time = QSharedPointer::create(); time->start(); const QByteArray bufferType = ENTITY_TYPE_MAIL; KPIM::Maildir maildir(path, true); if (!maildir.isValid()) { - Warning() << "Failed to sync folder."; + SinkWarning() << "Failed to sync folder."; return; } - Trace() << "Importing new mail."; + SinkTrace() << "Importing new mail."; maildir.importNewMails(); auto listingPath = maildir.pathToCurrent(); auto entryIterator = QSharedPointer::create(listingPath, QDir::Files); - Trace() << "Looking into " << listingPath; + SinkTrace() << "Looking into " << listingPath; const auto folderLocalId = syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, path.toUtf8()); @@ -332,7 +331,7 @@ public: callback(sinkId); }, [&](const Index::Error &error) { - Warning() << "Error in index: " << error.message << property; + SinkWarning() << "Error in index: " << error.message << property; }); }, [](const QByteArray &remoteId) -> bool { @@ -350,7 +349,7 @@ public: const auto flags = maildir.readEntryFlags(fileName); const auto maildirKey = maildir.getKeyFromFile(fileName); - Trace() << "Found a mail " << filePath << " : " << fileName; + SinkTrace() << "Found a mail " << filePath << " : " << fileName; Sink::ApplicationDomain::Mail mail; mail.setProperty("folder", folderLocalId); @@ -362,12 +361,12 @@ public: createOrModify(bufferType, remoteId, mail); } const auto elapsed = time->elapsed(); - Log() << "Synchronized " << count << " mails in " << listingPath << Sink::Log::TraceTime(elapsed) << " " << elapsed/qMax(count, 1) << " [ms/mail]"; + SinkLog() << "Synchronized " << count << " mails in " << listingPath << Sink::Log::TraceTime(elapsed) << " " << elapsed/qMax(count, 1) << " [ms/mail]"; } KAsync::Job synchronizeWithSource() Q_DECL_OVERRIDE { - Log() << " Synchronizing"; + SinkLog() << " Synchronizing"; return KAsync::start >([this]() { KPIM::Maildir maildir(mMaildirPath, true); if (!maildir.isValid(false)) { @@ -381,7 +380,7 @@ public: //Don't let the transaction grow too much commit(); } - Log() << "Done Synchronizing"; + SinkLog() << "Done Synchronizing"; return KAsync::null(); }); } @@ -402,15 +401,15 @@ public: { if (operation == Sink::Operation_Creation) { const auto remoteId = getFilePathFromMimeMessagePath(mail.getMimeMessagePath()); - Trace() << "Mail created: " << remoteId; + SinkTrace() << "Mail created: " << remoteId; return KAsync::start([=]() -> QByteArray { return remoteId.toUtf8(); }); } else if (operation == Sink::Operation_Removal) { - Trace() << "Removing a mail: " << oldRemoteId; + SinkTrace() << "Removing a mail: " << oldRemoteId; return KAsync::null(); } else if (operation == Sink::Operation_Modification) { - Trace() << "Modifying a mail: " << oldRemoteId; + SinkTrace() << "Modifying a mail: " << oldRemoteId; const auto remoteId = getFilePathFromMimeMessagePath(mail.getMimeMessagePath()); return KAsync::start([=]() -> QByteArray { return remoteId.toUtf8(); @@ -425,7 +424,7 @@ public: auto folderName = folder.getName(); //FIXME handle non toplevel folders auto path = mMaildirPath + "/" + folderName; - Trace() << "Creating a new folder: " << path; + SinkTrace() << "Creating a new folder: " << path; KPIM::Maildir maildir(path, false); maildir.create(); return KAsync::start([=]() -> QByteArray { @@ -433,12 +432,12 @@ public: }); } else if (operation == Sink::Operation_Removal) { const auto path = oldRemoteId; - Trace() << "Removing a folder: " << path; + SinkTrace() << "Removing a folder: " << path; KPIM::Maildir maildir(path, false); maildir.remove(); return KAsync::null(); } else if (operation == Sink::Operation_Modification) { - Warning() << "Folder modifications are not implemented"; + SinkWarning() << "Folder modifications are not implemented"; return KAsync::start([=]() -> QByteArray { return oldRemoteId; }); @@ -472,7 +471,7 @@ MaildirResource::MaildirResource(const QByteArray &instanceIdentifier, const QSh setupPreprocessors(ENTITY_TYPE_FOLDER, QVector() << new FolderPreprocessor(mMaildirPath) << new DefaultIndexUpdater); KPIM::Maildir dir(mMaildirPath, true); - Trace() << "Started maildir resource for maildir: " << mMaildirPath; + SinkTrace() << "Started maildir resource for maildir: " << mMaildirPath; { auto draftsFolder = dir.addSubFolder("Drafts"); auto remoteId = synchronizer->createFolder(draftsFolder, "folder", QByteArrayList() << "drafts"); @@ -503,7 +502,7 @@ KAsync::Job MaildirResource::inspect(int inspectionType, const QByteArray auto entityStore = QSharedPointer::create(mResourceType, mResourceInstanceIdentifier, transaction); auto syncStore = QSharedPointer::create(synchronizationTransaction); - Trace() << "Inspecting " << inspectionType << domainType << entityId << property << expectedValue; + SinkTrace() << "Inspecting " << inspectionType << domainType << entityId << property << expectedValue; if (domainType == ENTITY_TYPE_MAIL) { auto mail = entityStore->read(entityId); @@ -542,7 +541,7 @@ KAsync::Job MaildirResource::inspect(int inspectionType, const QByteArray auto folder = entityStore->read(entityId); if (inspectionType == Sink::ResourceControl::Inspection::CacheIntegrityInspectionType) { - Trace() << "Inspecting cache integrity" << remoteId; + SinkTrace() << "Inspecting cache integrity" << remoteId; if (!QDir(remoteId).exists()) { return KAsync::error(1, "The directory is not existing: " + remoteId); } @@ -553,14 +552,14 @@ KAsync::Job MaildirResource::inspect(int inspectionType, const QByteArray expectedCount++; }, [&](const Index::Error &error) { - Warning() << "Error in index: " << error.message << property; + SinkWarning() << "Error in index: " << error.message << property; }); QDir dir(remoteId + "/cur"); const QFileInfoList list = dir.entryInfoList(QDir::Files); if (list.size() != expectedCount) { for (const auto &fileInfo : list) { - Warning() << "Found in cache: " << fileInfo.fileName(); + SinkWarning() << "Found in cache: " << fileInfo.fileName(); } return KAsync::error(1, QString("Wrong number of files; found %1 instead of %2.").arg(list.size()).arg(expectedCount)); } diff --git a/examples/mailtransportresource/mailtransportresource.cpp b/examples/mailtransportresource/mailtransportresource.cpp index 1e93bdf..a729d4d 100644 --- a/examples/mailtransportresource/mailtransportresource.cpp +++ b/examples/mailtransportresource/mailtransportresource.cpp @@ -44,6 +44,8 @@ #define ENTITY_TYPE_MAIL "mail" +SINK_DEBUG_AREA("mailtransportresource") + using namespace Sink; //TODO fold into synchronizer @@ -58,7 +60,7 @@ public: KAsync::Job replay(const ApplicationDomain::Mail &mail, Sink::Operation operation, const QByteArray &oldRemoteId, const QList &changedProperties) Q_DECL_OVERRIDE { if (operation == Sink::Operation_Creation) { - Trace() << "Dispatching message."; + SinkTrace() << "Dispatching message."; // return send(mail, mSettings); } else if (operation == Sink::Operation_Removal) { } else if (operation == Sink::Operation_Modification) { @@ -86,9 +88,9 @@ public: msg->setHead(KMime::CRLFtoLF(data)); msg->parse(); if (settings.testMode) { - Log() << "I would totally send that mail, but I'm in test mode." << mail.identifier(); + SinkLog() << "I would totally send that mail, but I'm in test mode." << mail.identifier(); auto path = resourceStorageLocation(mResourceInstanceIdentifier) + "/test/"; - Trace() << path; + SinkTrace() << path; QDir dir; dir.mkpath(path); QFile f(path+ mail.identifier()); @@ -97,9 +99,9 @@ public: f.close(); } else { if (MailTransport::sendMessage(msg, settings.server.toUtf8(), settings.username.toUtf8(), settings.password.toUtf8(), settings.cacert.toUtf8())) { - Log() << "Sent message successfully"; + SinkLog() << "Sent message successfully"; } else { - Log() << "Failed to send message"; + SinkLog() << "Failed to send message"; return KAsync::error(1, "Failed to send the message."); } } @@ -108,13 +110,13 @@ public: KAsync::Job synchronizeWithSource() Q_DECL_OVERRIDE { - Log() << " Synchronizing"; + SinkLog() << " Synchronizing"; return KAsync::start([this](KAsync::Future future) { Sink::Query query; QList toSend; - Log() << " Looking for mail"; + SinkLog() << " Looking for mail"; store().reader().query(query, [&](const ApplicationDomain::Mail &mail) -> bool { - Trace() << "Found mail: " << mail.identifier(); + SinkTrace() << "Found mail: " << mail.identifier(); if (!mail.getSent()) { toSend << mail; } -- cgit v1.2.3