diff options
author | Patrick Ohly <patrick.ohly@intel.com> | 2013-04-08 18:57:11 +0200 |
---|---|---|
committer | Patrick Ohly <patrick.ohly@intel.com> | 2013-05-06 16:28:12 +0200 |
commit | b5befe6cbf450346678a9a5d79ba885be9bd5dab (patch) | |
tree | b0b01da93b2ac0c4c2a826436ef5bbac40c3ccf2 /src | |
parent | 77b26de4b8bd09edf37adbeeff3b640a535ed1d5 (diff) |
Logging: remove usage of Logger instance
Passing an explicit Logger instance to the SE_LOG* macros was hardly
ever used and only made the macros more complex.
The only usage of it was in some backends, which then added a prefix
string automatically. The same effect can be achieved by passing
getDisplayName(). Exception handling no longer needs a Logger instance,
the prefix alone is enough.
The other intended usage, avoiding global variables for logging by
passing a logger known to the caller, was not possible at all.
To make prefix handling more flexible, it is now passed as a "const
std::string *" instead of a "const char *".
Diffstat (limited to 'src')
32 files changed, 175 insertions, 184 deletions
diff --git a/src/backends/activesync/ActiveSyncCalendarSource.cpp b/src/backends/activesync/ActiveSyncCalendarSource.cpp index c6f665fb..613c9564 100644 --- a/src/backends/activesync/ActiveSyncCalendarSource.cpp +++ b/src/backends/activesync/ActiveSyncCalendarSource.cpp @@ -50,10 +50,10 @@ void ActiveSyncCalendarSource::beginSync(const std::string &lastToken, const std setStartSyncKey(lastToken); if (lastToken.empty()) { // slow sync: wipe out cached list of IDs, will be filled anew below - SE_LOG_DEBUG(this, NULL, "sync key empty, starting slow sync"); + SE_LOG_DEBUG(NULL, getDisplayName(), "sync key empty, starting slow sync"); m_trackingNode->clear(); } else { - SE_LOG_DEBUG(this, NULL, "sync key %s, starting incremental sync", lastToken.c_str()); + SE_LOG_DEBUG(NULL, getDisplayName(), "sync key %s, starting incremental sync", lastToken.c_str()); // re-populate cache from storage, without any item data ConfigProps props; @@ -87,7 +87,7 @@ void ActiveSyncCalendarSource::beginSync(const std::string &lastToken, const std } } if (!okay) { - SE_LOG_DEBUG(this, NULL, "unsupported or corrupt revision entry: %s = %s", + SE_LOG_DEBUG(NULL, getDisplayName(), "unsupported or corrupt revision entry: %s = %s", easid.c_str(), value.c_str()); } @@ -150,13 +150,13 @@ void ActiveSyncCalendarSource::beginSync(const std::string &lastToken, const std if (easid.empty()) { throwError("empty server ID for new eas item"); } - SE_LOG_DEBUG(this, NULL, "new eas item %s", easid.c_str()); + SE_LOG_DEBUG(NULL, getDisplayName(), "new eas item %s", easid.c_str()); if (!item->data) { throwError(StringPrintf("no body returned for new eas item %s", easid.c_str())); } Event &event = setItemData(easid, item->data); BOOST_FOREACH(const std::string &subid, event.m_subids) { - SE_LOG_DEBUG(this, NULL, "new eas item %s = uid %s + rid %s", + SE_LOG_DEBUG(NULL, getDisplayName(), "new eas item %s = uid %s + rid %s", easid.c_str(), event.m_uid.c_str(), subid.c_str()); addItem(createLUID(easid, subid), NEW); } @@ -169,13 +169,13 @@ void ActiveSyncCalendarSource::beginSync(const std::string &lastToken, const std if (easid.empty()) { throwError("empty server ID for updated eas item"); } - SE_LOG_DEBUG(this, NULL, "updated eas item %s", easid.c_str()); + SE_LOG_DEBUG(NULL, getDisplayName(), "updated eas item %s", easid.c_str()); if (!item->data) { throwError(StringPrintf("no body returned for updated eas item %s", easid.c_str())); } Event &event = setItemData(easid, item->data); BOOST_FOREACH(const std::string &subid, event.m_subids) { - SE_LOG_DEBUG(this, NULL, "deleted eas item %s = uid %s + rid %s", + SE_LOG_DEBUG(NULL, getDisplayName(), "deleted eas item %s = uid %s + rid %s", easid.c_str(), event.m_uid.c_str(), subid.c_str()); addItem(createLUID(easid, subid), UPDATED); } @@ -190,10 +190,10 @@ void ActiveSyncCalendarSource::beginSync(const std::string &lastToken, const std } Event &event = findItem(easid); if (event.m_subids.empty()) { - SE_LOG_DEBUG(this, NULL, "deleted eas item %s empty?!", easid.c_str()); + SE_LOG_DEBUG(NULL, getDisplayName(), "deleted eas item %s empty?!", easid.c_str()); } else { BOOST_FOREACH(const std::string &subid, event.m_subids) { - SE_LOG_DEBUG(this, NULL, "deleted eas item %s = uid %s + rid %s", + SE_LOG_DEBUG(NULL, getDisplayName(), "deleted eas item %s = uid %s + rid %s", easid.c_str(), event.m_uid.c_str(), subid.c_str()); addItem(createLUID(easid, subid), DELETED); } @@ -222,7 +222,7 @@ void ActiveSyncCalendarSource::beginSync(const std::string &lastToken, const std const std::string &easid = entry.first; const boost::shared_ptr<Event> &eventptr = entry.second; BOOST_FOREACH(const std::string &subid, eventptr->m_subids) { - SE_LOG_DEBUG(this, NULL, "existing eas item %s = uid %s + rid %s", + SE_LOG_DEBUG(NULL, getDisplayName(), "existing eas item %s = uid %s + rid %s", easid.c_str(), eventptr->m_uid.c_str(), subid.c_str()); addItem(createLUID(easid, subid), ANY); } @@ -253,7 +253,7 @@ std::string ActiveSyncCalendarSource::endSync(bool success) m_trackingNode->flush(); std::string newSyncKey = getCurrentSyncKey(); - SE_LOG_DEBUG(this, NULL, "next sync key %s", newSyncKey.empty() ? "empty" : newSyncKey.c_str()); + SE_LOG_DEBUG(NULL, getDisplayName(), "next sync key %s", newSyncKey.empty() ? "empty" : newSyncKey.c_str()); return newSyncKey; } diff --git a/src/backends/activesync/ActiveSyncSource.cpp b/src/backends/activesync/ActiveSyncSource.cpp index d48e119f..b6971f74 100644 --- a/src/backends/activesync/ActiveSyncSource.cpp +++ b/src/backends/activesync/ActiveSyncSource.cpp @@ -241,10 +241,10 @@ void ActiveSyncSource::beginSync(const std::string &lastToken, const std::string m_startSyncKey = lastToken; if (lastToken.empty()) { // slow sync: wipe out cached list of IDs, will be filled anew below - SE_LOG_DEBUG(this, NULL, "sync key empty, starting slow sync"); + SE_LOG_DEBUG(NULL, getDisplayName(), "sync key empty, starting slow sync"); m_ids->clear(); } else { - SE_LOG_DEBUG(this, NULL, "sync key %s for account '%s' folder '%s', starting incremental sync", + SE_LOG_DEBUG(NULL, getDisplayName(), "sync key %s for account '%s' folder '%s', starting incremental sync", lastToken.c_str(), m_account.c_str(), m_folder.c_str()); @@ -305,7 +305,7 @@ void ActiveSyncSource::beginSync(const std::string &lastToken, const std::string if (luid.empty()) { throwError("empty server ID for new eas item"); } - SE_LOG_DEBUG(this, NULL, "new item %s", luid.c_str()); + SE_LOG_DEBUG(NULL, getDisplayName(), "new item %s", luid.c_str()); addItem(luid, NEW); m_ids->setProperty(luid, "1"); if (!item->data) { @@ -321,7 +321,7 @@ void ActiveSyncSource::beginSync(const std::string &lastToken, const std::string if (luid.empty()) { throwError("empty server ID for updated eas item"); } - SE_LOG_DEBUG(this, NULL, "updated item %s", luid.c_str()); + SE_LOG_DEBUG(NULL, getDisplayName(), "updated item %s", luid.c_str()); addItem(luid, UPDATED); // m_ids.setProperty(luid, "1"); not necessary, should already exist (TODO: check?!) if (!item->data) { @@ -337,7 +337,7 @@ void ActiveSyncSource::beginSync(const std::string &lastToken, const std::string if (luid.empty()) { throwError("empty server ID for deleted eas item"); } - SE_LOG_DEBUG(this, NULL, "deleted item %s", luid.c_str()); + SE_LOG_DEBUG(NULL, getDisplayName(), "deleted item %s", luid.c_str()); addItem(luid, DELETED); m_ids->removeProperty(luid); } @@ -363,7 +363,7 @@ void ActiveSyncSource::beginSync(const std::string &lastToken, const std::string m_ids->readProperties(props); BOOST_FOREACH(const StringPair &entry, props) { const std::string &luid = entry.first; - SE_LOG_DEBUG(this, NULL, "existing item %s", luid.c_str()); + SE_LOG_DEBUG(NULL, getDisplayName(), "existing item %s", luid.c_str()); addItem(luid, ANY); } @@ -386,7 +386,7 @@ std::string ActiveSyncSource::endSync(bool success) // let engine do incremental sync next time or start from scratch // in case of failure std::string newSyncKey = success ? m_currentSyncKey : ""; - SE_LOG_DEBUG(this, NULL, "next sync key %s", newSyncKey.empty() ? "empty" : newSyncKey.c_str()); + SE_LOG_DEBUG(NULL, getDisplayName(), "next sync key %s", newSyncKey.empty() ? "empty" : newSyncKey.c_str()); return newSyncKey; } diff --git a/src/backends/addressbook/AddressBookSource.cpp b/src/backends/addressbook/AddressBookSource.cpp index d43bc978..91499381 100644 --- a/src/backends/addressbook/AddressBookSource.cpp +++ b/src/backends/addressbook/AddressBookSource.cpp @@ -1230,7 +1230,7 @@ void AddressBookSource::listAllItems(RevisionMap_t &revisions) void AddressBookSource::close() { if (m_addressbook && !hasFailed()) { - SE_LOG_DEBUG(this, NULL, "flushing address book"); + SE_LOG_DEBUG(NULL, getDisplayName(), "flushing address book"); // store changes persistently if (!ABSave(m_addressbook)) { throwError("saving address book"); @@ -1241,7 +1241,7 @@ void AddressBookSource::close() // sleep a bit before returning control sleep(2); - SE_LOG_DEBUG(this, NULL, "done with address book"); + SE_LOG_DEBUG(NULL, getDisplayName(), "done with address book"); } m_addressbook = NULL; @@ -1272,7 +1272,7 @@ SyncItem *AddressBookSource::createItem(const string &uid, bool asVCard30) #ifdef USE_ADDRESS_BOOK_VCARD ref<CFDataRef> vcard(ABPersonCopyVCardRepresentation(person), "vcard"); - SE_LOG_DEBUG(this, NULL, "%*s", (int)CFDataGetLength(vcard), (const char *)CFDataGetBytePtr(vcard)); + SE_LOG_DEBUG(NULL, getDisplayName(), "%*s", (int)CFDataGetLength(vcard), (const char *)CFDataGetBytePtr(vcard)); item->setData(CFDataGetBytePtr(vcard), CFDataGetLength(vcard)); #else string vcard; @@ -1319,7 +1319,7 @@ AddressBookSource::InsertItemResult AddressBookSource::insertItem(const string & person.set(PersonCreateWrapper(m_addressbook), "contact"); } try { - SE_LOG_DEBUG(this, NULL, "storing vCard for %s:\n%s", + SE_LOG_DEBUG(NULL, getDisplayName(), "storing vCard for %s:\n%s", update ? luid.c_str() : "new contact", data.c_str()); vCard2ABPerson converter(data, person); @@ -1367,7 +1367,7 @@ void AddressBookSource::deleteItem(const string &uid) throwError(string("deleting contact ") + uid); } } else { - SE_LOG_DEBUG(this, NULL, "%s: %s: request to delete non-existant contact ignored", + SE_LOG_DEBUG(NULL, getDisplayName(), "%s: %s: request to delete non-existant contact ignored", getName(), uid.c_str()); } } diff --git a/src/backends/evolution/EvolutionCalendarSource.cpp b/src/backends/evolution/EvolutionCalendarSource.cpp index dc52601c..0fd75ce9 100644 --- a/src/backends/evolution/EvolutionCalendarSource.cpp +++ b/src/backends/evolution/EvolutionCalendarSource.cpp @@ -197,7 +197,7 @@ char *EvolutionCalendarSource::authenticate(const char *prompt, { std::string passwd = getPassword(); - SE_LOG_DEBUG(this, NULL, "authentication requested, prompt \"%s\", key \"%s\" => %s", + SE_LOG_DEBUG(NULL, getDisplayName(), "authentication requested, prompt \"%s\", key \"%s\" => %s", prompt, key, !passwd.empty() ? "returning configured password" : "no password configured"); return !passwd.empty() ? strdup(passwd.c_str()) : NULL; @@ -501,7 +501,7 @@ EvolutionCalendarSource::InsertItemResult EvolutionCalendarSource::insertItem(co propstart = data.find("\nCATEGORIES", propstart + 1); } if (modified) { - SE_LOG_DEBUG(this, NULL, "after replacing , with \\, in CATEGORIES:\n%s", data.c_str()); + SE_LOG_DEBUG(NULL, getDisplayName(), "after replacing , with \\, in CATEGORIES:\n%s", data.c_str()); } eptr<icalcomponent> icomp(icalcomponent_new_from_string((char *)data.c_str())); @@ -545,7 +545,7 @@ EvolutionCalendarSource::InsertItemResult EvolutionCalendarSource::insertItem(co const char *tzid = icaltimezone_get_tzid(zone); if (!tzid || !tzid[0]) { // cannot add a VTIMEZONE without TZID - SE_LOG_DEBUG(this, NULL, "skipping VTIMEZONE without TZID"); + SE_LOG_DEBUG(NULL, getDisplayName(), "skipping VTIMEZONE without TZID"); } else { gboolean success = #ifdef USE_EDS_CLIENT @@ -832,7 +832,7 @@ EvolutionCalendarSource::ICalComps_t EvolutionCalendarSource::removeEvents(const #endif ) { if (IsCalObjNotFound(gerror)) { - SE_LOG_DEBUG(this, NULL, "%s: request to delete non-existant item ignored", + SE_LOG_DEBUG(NULL, getDisplayName(), "%s: request to delete non-existant item ignored", uid.c_str()); if (!ignoreNotFound) { throwError(STATUS_NOT_FOUND, string("delete item: ") + uid); @@ -920,7 +920,7 @@ void EvolutionCalendarSource::removeItem(const string &luid) ; if (!item || (!success && IsCalObjNotFound(gerror))) { - SE_LOG_DEBUG(this, NULL, "%s: request to delete non-existant item", + SE_LOG_DEBUG(NULL, getDisplayName(), "%s: request to delete non-existant item", luid.c_str()); throwError(STATUS_NOT_FOUND, string("delete item: ") + id.getLUID()); } else if (!success) { @@ -1034,7 +1034,7 @@ string EvolutionCalendarSource::retrieveItemAsString(const ItemID &id) if (!icalstr) { throwError(string("could not encode item as iCalendar: ") + id.getLUID()); } else { - SE_LOG_DEBUG(this, NULL, "had to remove TZIDs because e_cal_get_component_as_string() failed for:\n%s", icalstr.get()); + SE_LOG_DEBUG(NULL, getDisplayName(), "had to remove TZIDs because e_cal_get_component_as_string() failed for:\n%s", icalstr.get()); } } @@ -1066,7 +1066,7 @@ string EvolutionCalendarSource::retrieveItemAsString(const ItemID &id) propstart = data.find("\nCATEGORIES", propstart + 1); } if (modified) { - SE_LOG_DEBUG(this, NULL, "after replacing \\, with , in CATEGORIES:\n%s", data.c_str()); + SE_LOG_DEBUG(NULL, getDisplayName(), "after replacing \\, with , in CATEGORIES:\n%s", data.c_str()); } return data; diff --git a/src/backends/evolution/EvolutionContactSource.cpp b/src/backends/evolution/EvolutionContactSource.cpp index cac9a226..e01072d3 100644 --- a/src/backends/evolution/EvolutionContactSource.cpp +++ b/src/backends/evolution/EvolutionContactSource.cpp @@ -222,7 +222,7 @@ void EvolutionContactSource::open() } while (authmethod) { const char *method = (const char *)authmethod->data; - SE_LOG_DEBUG(this, NULL, "trying authentication method \"%s\", user %s, password %s", + SE_LOG_DEBUG(NULL, getDisplayName(), "trying authentication method \"%s\", user %s, password %s", method, !user.empty() ? "configured" : "not configured", !passwd.empty() ? "configured" : "not configured"); @@ -231,10 +231,10 @@ void EvolutionContactSource::open() passwd.c_str(), method, gerror)) { - SE_LOG_DEBUG(this, NULL, "authentication succeeded"); + SE_LOG_DEBUG(NULL, getDisplayName(), "authentication succeeded"); break; } else { - SE_LOG_ERROR(this, NULL, "authentication failed: %s", gerror->message); + SE_LOG_ERROR(NULL, getDisplayName(), "authentication failed: %s", gerror->message); } authmethod = authmethod->next; } @@ -361,7 +361,7 @@ void EvolutionContactSource::listAllItems(RevisionMap_t &revisions) interesting_field_list.push_back(e_contact_field_name (E_CONTACT_REV)); e_book_client_view_set_fields_of_interest (viewPtr, interesting_field_list, gerror); if (gerror) { - SE_LOG_ERROR(this, NULL, "e_book_client_view_set_fields_of_interest: %s", (const char*)gerror); + SE_LOG_ERROR(NULL, getDisplayName(), "e_book_client_view_set_fields_of_interest: %s", (const char*)gerror); gerror.clear(); } diff --git a/src/backends/evolution/EvolutionSyncSource.cpp b/src/backends/evolution/EvolutionSyncSource.cpp index d94a4448..ea814f80 100644 --- a/src/backends/evolution/EvolutionSyncSource.cpp +++ b/src/backends/evolution/EvolutionSyncSource.cpp @@ -47,7 +47,7 @@ void EvolutionSyncSource::getDatabasesFromRegistry(SyncSource::Databases &result static void handleErrorCB(EClient */*client*/, const gchar *error_msg, gpointer user_data) { EvolutionSyncSource *that = static_cast<EvolutionSyncSource *>(user_data); - SE_LOG_ERROR(that, NULL, "%s", error_msg); + SE_LOG_ERROR(NULL, that->getDisplayName(), "%s", error_msg); } EClientCXX EvolutionSyncSource::openESource(const char *extension, diff --git a/src/backends/webdav/CalDAVSource.cpp b/src/backends/webdav/CalDAVSource.cpp index decd1704..cfa226d6 100644 --- a/src/backends/webdav/CalDAVSource.cpp +++ b/src/backends/webdav/CalDAVSource.cpp @@ -513,7 +513,7 @@ SubSyncSource::SubItemResult CalDAVSource::insertSubItem(const std::string &luid Event::escapeRecurrenceID(buffer); data = &buffer; } - SE_LOG_DEBUG(this, NULL, "inserting new VEVENT"); + SE_LOG_DEBUG(NULL, getDisplayName(), "inserting new VEVENT"); res = insertItem(name, *data, true); subres.m_mainid = res.m_luid; subres.m_uid = newEvent->m_UID; @@ -720,7 +720,7 @@ SubSyncSource::SubItemResult CalDAVSource::insertSubItem(const std::string &luid // TODO: avoid updating item on server immediately? try { - SE_LOG_DEBUG(this, NULL, "updating VEVENT"); + SE_LOG_DEBUG(NULL, getDisplayName(), "updating VEVENT"); InsertItemResult res = insertItem(event.m_DAVluid, data, true); if (res.m_state != ITEM_OKAY || res.m_luid != event.m_DAVluid) { @@ -749,7 +749,7 @@ SubSyncSource::SubItemResult CalDAVSource::insertSubItem(const std::string &luid // a detached recurrence had to be added to an existing meeting // series. Ignoring the problem means would keep the detached // recurrence out of the server permanently. - SE_LOG_INFO(this, NULL, "%s: not updated because CalDAV server refused write access for it", + SE_LOG_INFO(NULL, getDisplayName(), "%s: not updated because CalDAV server refused write access for it", getSubDescription(event, subid).c_str()); subres.m_merged = true; subres.m_revision = event.m_etag; @@ -913,7 +913,7 @@ std::string CalDAVSource::removeSubItem(const string &davLUID, const std::string if (event.m_subids.size() == 1) { // remove entire merged item, nothing will be left after removal if (*event.m_subids.begin() != subid) { - SE_LOG_DEBUG(this, NULL, "%s: request to remove the %s recurrence: only the %s recurrence exists", + SE_LOG_DEBUG(NULL, getDisplayName(), "%s: request to remove the %s recurrence: only the %s recurrence exists", davLUID.c_str(), SubIDName(subid).c_str(), SubIDName(*event.m_subids.begin()).c_str()); @@ -945,7 +945,7 @@ std::string CalDAVSource::removeSubItem(const string &davLUID, const std::string } } if (updated) { - SE_LOG_DEBUG(this, NULL, "Google recurring event delete hack: remove RRULE before deleting"); + SE_LOG_DEBUG(NULL, getDisplayName(), "Google recurring event delete hack: remove RRULE before deleting"); eptr<char> icalstr(ical_strdup(icalcomponent_as_ical_string(event.m_calendar))); insertSubItem(davLUID, subid, icalstr.get()); // It has been observed that trying the DELETE immediately @@ -956,13 +956,13 @@ std::string CalDAVSource::removeSubItem(const string &davLUID, const std::string // try a few times before giving up. for (int retry = 0; retry < 5; retry++) { try { - SE_LOG_DEBUG(this, NULL, "Google recurring event delete hack: remove event, attempt #%d", retry); + SE_LOG_DEBUG(NULL, getDisplayName(), "Google recurring event delete hack: remove event, attempt #%d", retry); removeSubItem(davLUID, subid); break; } catch (const TransportStatusException &ex2) { if (ex2.syncMLStatus() == 409 && strstr(ex2.what(), "Can't delete a recurring event")) { - SE_LOG_DEBUG(this, NULL, "Google recurring event delete hack: try again in a second"); + SE_LOG_DEBUG(NULL, getDisplayName(), "Google recurring event delete hack: try again in a second"); Sleep(1); } else { throw; @@ -970,7 +970,7 @@ std::string CalDAVSource::removeSubItem(const string &davLUID, const std::string } } } else { - SE_LOG_DEBUG(this, NULL, "Google recurring event delete hack not applicable, giving up"); + SE_LOG_DEBUG(NULL, getDisplayName(), "Google recurring event delete hack not applicable, giving up"); throw; } } else { @@ -1031,7 +1031,7 @@ void CalDAVSource::removeMergedItem(const std::string &davLUID) EventCache::iterator it = m_cache.find(davLUID); if (it == m_cache.end()) { // gone already, no need to do anything - SE_LOG_DEBUG(this, NULL, "%s: ignoring request to delete non-existent item", + SE_LOG_DEBUG(NULL, getDisplayName(), "%s: ignoring request to delete non-existent item", davLUID.c_str()); return; } diff --git a/src/backends/webdav/WebDAVSource.cpp b/src/backends/webdav/WebDAVSource.cpp index 1c93fc35..3ff90f8a 100644 --- a/src/backends/webdav/WebDAVSource.cpp +++ b/src/backends/webdav/WebDAVSource.cpp @@ -567,7 +567,7 @@ bool WebDAVSource::findCollections(const boost::function<bool (const std::string bool res = true; // completed int timeoutSeconds = m_settings->timeoutSeconds(); int retrySeconds = m_settings->retrySeconds(); - SE_LOG_DEBUG(this, NULL, "timout %ds, retry %ds => %s", + SE_LOG_DEBUG(NULL, getDisplayName(), "timout %ds, retry %ds => %s", timeoutSeconds, retrySeconds, (timeoutSeconds <= 0 || retrySeconds <= 0) ? "resending disabled" : "resending allowed"); @@ -612,7 +612,7 @@ bool WebDAVSource::findCollections(const boost::function<bool (const std::string } buffer[read] = 0; m_contextSettings->setURL(buffer); - SE_LOG_DEBUG(this, NULL, "found syncURL '%s' via DNS SRV", buffer); + SE_LOG_DEBUG(NULL, getDisplayName(), "found syncURL '%s' via DNS SRV", buffer); int res = pclose(in); in = NULL; switch (res) { @@ -629,12 +629,12 @@ bool WebDAVSource::findCollections(const boost::function<bool (const std::string if (retrySeconds > 0 && timeoutSeconds > 0) { if (now < startTime + timeoutSeconds) { - SE_LOG_DEBUG(this, NULL, "DNS SRV search failed due to network issues, retry in %d seconds", + SE_LOG_DEBUG(NULL, getDisplayName(), "DNS SRV search failed due to network issues, retry in %d seconds", retrySeconds); Sleep(retrySeconds); goto retry; } else { - SE_LOG_INFO(this, NULL, "DNS SRV search timed out after %d seconds", timeoutSeconds); + SE_LOG_INFO(NULL, getDisplayName(), "DNS SRV search timed out after %d seconds", timeoutSeconds); } } @@ -1293,7 +1293,7 @@ void WebDAVSource::getSynthesisInfo(SynthesisInfo &info, " <include rule=\"ALL\"/>\n" " </remoterule>"; } - SE_LOG_DEBUG(this, NULL, "using data conversion rules for '%s'", info.m_backendRule.c_str()); + SE_LOG_DEBUG(NULL, getDisplayName(), "using data conversion rules for '%s'", info.m_backendRule.c_str()); } } diff --git a/src/dbus/server/server.cpp b/src/dbus/server/server.cpp index 3974e861..663189a0 100644 --- a/src/dbus/server/server.cpp +++ b/src/dbus/server/server.cpp @@ -910,7 +910,7 @@ void Server::updateDevice(const string &deviceId, } void Server::messagev(Level level, - const char *prefix, + const std::string *prefix, const char *file, int line, const char *function, diff --git a/src/dbus/server/server.h b/src/dbus/server/server.h index e0e75c0f..59dd5496 100644 --- a/src/dbus/server/server.h +++ b/src/dbus/server/server.h @@ -659,7 +659,7 @@ public: * but also send them as signals to clients */ virtual void messagev(Level level, - const char *prefix, + const std::string *prefix, const char *file, int line, const char *function, @@ -671,7 +671,7 @@ public: getProcessName()); } void messagev(Level level, - const char *prefix, + const std::string *prefix, const char *file, int line, const char *function, diff --git a/src/dbus/server/session-helper.cpp b/src/dbus/server/session-helper.cpp index 247c63a7..a22be21e 100644 --- a/src/dbus/server/session-helper.cpp +++ b/src/dbus/server/session-helper.cpp @@ -83,7 +83,7 @@ static void dumpString(const std::string &output) } void SessionHelper::messagev(Level level, - const char *prefix, + const std::string *prefix, const char *file, int line, const char *function, diff --git a/src/dbus/server/session-helper.h b/src/dbus/server/session-helper.h index 660782ca..667a4e6e 100644 --- a/src/dbus/server/session-helper.h +++ b/src/dbus/server/session-helper.h @@ -83,7 +83,7 @@ class SessionHelper : public GDBusCXX::DBusObjectHelper, // Logger implementation -> output via D-Bus emitLogOutput virtual void messagev(Level level, - const char *prefix, + const std::string *prefix, const char *file, int line, const char *function, diff --git a/src/dbus/server/session.cpp b/src/dbus/server/session.cpp index fcb50f3c..c6e00b72 100644 --- a/src/dbus/server/session.cpp +++ b/src/dbus/server/session.cpp @@ -805,7 +805,7 @@ void Session::useHelperAsync(const SimpleResult &result) } void Session::messagev(Level level, - const char *prefix, + const std::string *prefix, const char *file, int line, const char *function, diff --git a/src/dbus/server/session.h b/src/dbus/server/session.h index 6df31327..0af9baba 100644 --- a/src/dbus/server/session.h +++ b/src/dbus/server/session.h @@ -348,7 +348,7 @@ private: * in the server which is related to the session. */ virtual void messagev(Level level, - const char *prefix, + const std::string *prefix, const char *file, int line, const char *function, diff --git a/src/syncevo/Cmdline.cpp b/src/syncevo/Cmdline.cpp index e3e57e5b..beb92c05 100644 --- a/src/syncevo/Cmdline.cpp +++ b/src/syncevo/Cmdline.cpp @@ -4464,7 +4464,7 @@ private: /** capture output produced while test ran */ void messagev(Level level, - const char *prefix, + const std::string *prefix, const char *file, int line, const char *function, diff --git a/src/syncevo/LocalTransportAgent.cpp b/src/syncevo/LocalTransportAgent.cpp index 7c64124d..dddc47b8 100644 --- a/src/syncevo/LocalTransportAgent.cpp +++ b/src/syncevo/LocalTransportAgent.cpp @@ -837,7 +837,7 @@ class LocalTransportAgentChild : public TransportAgent, private LoggerBase * Write message into our own log and send to parent. */ virtual void messagev(Level level, - const char *prefix, + const std::string *prefix, const char *file, int line, const char *function, diff --git a/src/syncevo/LogRedirect.cpp b/src/syncevo/LogRedirect.cpp index 67c71a09..30db2ba5 100644 --- a/src/syncevo/LogRedirect.cpp +++ b/src/syncevo/LogRedirect.cpp @@ -220,7 +220,7 @@ void LogRedirect::restore() throw() } void LogRedirect::messagev(Level level, - const char *prefix, + const std::string *prefix, const char *file, int line, const char *function, @@ -430,7 +430,7 @@ bool LogRedirect::process(FDs &fds) throw() // Now pass it to logger, with a level determined by // the channel. This is the point where we can filter // out known noise. - const char *prefix = NULL; + std::string prefix; Logger::Level level = Logger::DEV; char *text = m_buffer; @@ -444,7 +444,7 @@ bool LogRedirect::process(FDs &fds) throw() if (eol) { m_stdoutData.append(text, eol - text); text = eol + 1; - LoggerBase::instance().message(level, prefix, + LoggerBase::instance().message(level, prefix.empty() ? NULL : &prefix, NULL, 0, NULL, "%s", m_stdoutData.c_str()); m_stdoutData.clear(); @@ -506,7 +506,7 @@ bool LogRedirect::process(FDs &fds) throw() if (len > 0 && text[len - 1] == '\n') { text[len - 1] = 0; } - LoggerBase::instance().message(level, prefix, + LoggerBase::instance().message(level, prefix.empty() ? NULL : &prefix, NULL, 0, NULL, "%s", text); available = 0; @@ -663,7 +663,7 @@ class LogRedirectTest : public CppUnit::TestFixture { } virtual void messagev(Level level, - const char *prefix, + const std::string *prefix, const char *file, int line, const char *function, diff --git a/src/syncevo/LogRedirect.h b/src/syncevo/LogRedirect.h index e52fc9cf..d2d32573 100644 --- a/src/syncevo/LogRedirect.h +++ b/src/syncevo/LogRedirect.h @@ -192,7 +192,7 @@ class LogRedirect : public LoggerStdout /** format log messages via normal LogStdout and print to a valid stream owned by us */ virtual void messagev(Level level, - const char *prefix, + const std::string *prefix, const char *file, int line, const char *function, diff --git a/src/syncevo/LogStdout.cpp b/src/syncevo/LogStdout.cpp index 6e36a44d..ca8f2b26 100644 --- a/src/syncevo/LogStdout.cpp +++ b/src/syncevo/LogStdout.cpp @@ -61,7 +61,7 @@ static void appendOutput(std::string &output, std::string &chunk, size_t expecte void LoggerStdout::messagev(FILE *file, Level msglevel, Level filelevel, - const char *prefix, + const std::string *prefix, const char *filename, int line, const char *function, @@ -83,7 +83,7 @@ void LoggerStdout::messagev(FILE *file, } void LoggerStdout::messagev(Level level, - const char *prefix, + const std::string *prefix, const char *file, int line, const char *function, diff --git a/src/syncevo/LogStdout.h b/src/syncevo/LogStdout.h index b3a099af..e3ed23ae 100644 --- a/src/syncevo/LogStdout.h +++ b/src/syncevo/LogStdout.h @@ -58,14 +58,14 @@ class LoggerStdout : public LoggerBase virtual void messagev(FILE *file, Level msglevel, Level filelevel, - const char *prefix, + const std::string *prefix, const char *filename, int line, const char *function, const char *format, va_list args); virtual void messagev(Level level, - const char *prefix, + const std::string *prefix, const char *file, int line, const char *function, diff --git a/src/syncevo/LogSyslog.cpp b/src/syncevo/LogSyslog.cpp index 31065d5c..e2d6c11f 100644 --- a/src/syncevo/LogSyslog.cpp +++ b/src/syncevo/LogSyslog.cpp @@ -67,7 +67,7 @@ static void printToSyslog(int sysloglevel, std::string &chunk, size_t expectedTo } void LoggerSyslog::messagev(Level level, - const char *prefix, + const std::string *prefix, const char *file, int line, const char *function, diff --git a/src/syncevo/LogSyslog.h b/src/syncevo/LogSyslog.h index 6276ec82..955d73b2 100644 --- a/src/syncevo/LogSyslog.h +++ b/src/syncevo/LogSyslog.h @@ -46,7 +46,7 @@ public: ~LoggerSyslog(); virtual void messagev(Level level, - const char *prefix, + const std::string *prefix, const char *file, int line, const char *function, diff --git a/src/syncevo/Logging.cpp b/src/syncevo/Logging.cpp index 6c0f0248..3bf3f9c1 100644 --- a/src/syncevo/Logging.cpp +++ b/src/syncevo/Logging.cpp @@ -81,7 +81,7 @@ LoggerBase *LoggerBase::loggerAt(int index) void LoggerBase::formatLines(Level msglevel, Level outputlevel, const std::string &processName, - const char *prefix, + const std::string *prefix, const char *format, va_list args, boost::function<void (std::string &buffer, size_t expectedTotal)> print) @@ -139,7 +139,7 @@ void LoggerBase::formatLines(Level msglevel, levelToStr(msglevel), procname.c_str(), reltime.c_str(), - prefix ? prefix : "", + prefix ? prefix->c_str() : "", prefix ? ": " : ""); } @@ -185,7 +185,7 @@ void LoggerBase::formatLines(Level msglevel, } void Logger::message(Level level, - const char *prefix, + const std::string *prefix, const char *file, int line, const char *function, @@ -198,6 +198,20 @@ void Logger::message(Level level, va_end(args); } +void Logger::message(Level level, + const std::string &prefix, + const char *file, + int line, + const char *function, + const char *format, + ...) +{ + va_list args; + va_start(args, format); + messagev(level, &prefix, file, line, function, format, args); + va_end(args); +} + const char *Logger::levelToStr(Level level) { switch (level) { @@ -260,12 +274,14 @@ int Logger::sysyncPrintf(FILE *stream, { va_list args; va_start(args, format); - const char prefix[] = "SYSYNC "; - if (strlen(format) >= sizeof(prefix) && - !memcmp(format, prefix, sizeof(prefix) - 1)) { - format += sizeof(prefix) - 1; + static const std::string prefix("SYSYNC"); + if (boost::starts_with(format, prefix) && + format[prefix.size()] == ' ') { + // Skip initial "SYSYNC " prefix, because it will get re-added + // in a better way (= to each line) via the prefix parameter. + format += prefix.size() + 1; } - LoggerBase::instance().messagev(DEBUG, "SYSYNC", NULL, 0, NULL, format, args); + LoggerBase::instance().messagev(DEBUG, &prefix, NULL, 0, NULL, format, args); va_end(args); return 0; diff --git a/src/syncevo/Logging.h b/src/syncevo/Logging.h index 53c8aa04..58888abb 100644 --- a/src/syncevo/Logging.h +++ b/src/syncevo/Logging.h @@ -164,21 +164,32 @@ class Logger * make copy with va_copy() if necessary! */ virtual void messagev(Level level, - const char *prefix, + const std::string *prefix, const char *file, int line, const char *function, const char *format, va_list args) = 0; - /** default: redirect into messagev() */ - virtual void message(Level level, - const char *prefix, - const char *file, - int line, - const char *function, - const char *format, - ...) + /** redirect into messagev() */ + void message(Level level, + const std::string *prefix, + const char *file, + int line, + const char *function, + const char *format, + ...) +#ifdef __GNUC__ + __attribute__((format(printf, 7, 8))) +#endif + ; + void message(Level level, + const std::string &prefix, + const char *file, + int line, + const char *function, + const char *format, + ...) #ifdef __GNUC__ __attribute__((format(printf, 7, 8))) #endif @@ -282,7 +293,7 @@ class LoggerBase : public Logger void formatLines(Level msglevel, Level outputlevel, const std::string &processName, - const char *prefix, + const std::string *prefix, const char *format, va_list args, boost::function<void (std::string &chunk, size_t expectedTotal)> print); diff --git a/src/syncevo/MapSyncSource.cpp b/src/syncevo/MapSyncSource.cpp index 6f20658e..5e28b4c5 100644 --- a/src/syncevo/MapSyncSource.cpp +++ b/src/syncevo/MapSyncSource.cpp @@ -104,7 +104,7 @@ void MapSyncSource::detectChanges(SyncSourceRevisions::ChangeMode mode) } } if (!okay) { - SE_LOG_DEBUG(this, NULL, "unsupported or corrupt revision entry: %s = %s", + SE_LOG_DEBUG(NULL, getDisplayName(), "unsupported or corrupt revision entry: %s = %s", mainid.c_str(), value.c_str()); } @@ -214,17 +214,17 @@ void MapSyncSource::beginSync(const std::string &lastToken, const std::string &r } // slow sync if token is empty if (token.empty()) { - SE_LOG_DEBUG(this, NULL, "slow sync or testing, do full item scan to detect changes"); + SE_LOG_DEBUG(NULL, getDisplayName(), "slow sync or testing, do full item scan to detect changes"); mode = SyncSourceRevisions::CHANGES_SLOW; } else { string oldRevision = m_metaNode->readProperty("databaseRevision"); if (!oldRevision.empty()) { string newRevision = m_sub->subDatabaseRevision(); - SE_LOG_DEBUG(this, NULL, "old database revision '%s', new revision '%s'", + SE_LOG_DEBUG(NULL, getDisplayName(), "old database revision '%s', new revision '%s'", oldRevision.c_str(), newRevision.c_str()); if (newRevision == oldRevision) { - SE_LOG_DEBUG(this, NULL, "revisions match, no item changes"); + SE_LOG_DEBUG(NULL, getDisplayName(), "revisions match, no item changes"); mode = SyncSourceRevisions::CHANGES_NONE; } @@ -235,7 +235,7 @@ void MapSyncSource::beginSync(const std::string &lastToken, const std::string &r } } if (mode == SyncSourceRevisions::CHANGES_FULL) { - SE_LOG_DEBUG(this, NULL, "using full item scan to detect changes"); + SE_LOG_DEBUG(NULL, getDisplayName(), "using full item scan to detect changes"); } detectChanges(mode); diff --git a/src/syncevo/SyncContext.cpp b/src/syncevo/SyncContext.cpp index f2bc3922..39f00ee4 100644 --- a/src/syncevo/SyncContext.cpp +++ b/src/syncevo/SyncContext.cpp @@ -731,7 +731,7 @@ public: virtual void messagev(Level level, - const char *prefix, + const std::string *prefix, const char *file, int line, const char *function, @@ -765,7 +765,7 @@ public: va_list argscopy; va_copy(argscopy, args); // once to Synthesis log, with full debugging - m_client.getEngine().doDebug(level, prefix, file, line, function, format, argscopy); + m_client.getEngine().doDebug(level, prefix ? prefix->c_str() : NULL, file, line, function, format, argscopy); va_end(argscopy); } } @@ -1793,13 +1793,13 @@ void SyncContext::displaySourceProgress(sysync::TProgressEventEnum type, SE_LOG_INFO(NULL, NULL, "authorization failed, check username '%s' and password", getSyncUsername().c_str()); break; case 403: - SE_LOG_INFO(&source, NULL, "log in succeeded, but server refuses access - contact server operator"); + SE_LOG_INFO(NULL, source.getDisplayName(), "log in succeeded, but server refuses access - contact server operator"); break; case 407: SE_LOG_INFO(NULL, NULL, "proxy authorization failed, check proxy username and password"); break; case 404: - SE_LOG_INFO(&source, NULL, "server database not found, check URI '%s'", source.getURINonEmpty().c_str()); + SE_LOG_INFO(NULL, source.getDisplayName(), "server database not found, check URI '%s'", source.getURINonEmpty().c_str()); break; case 0: break; @@ -1812,7 +1812,7 @@ void SyncContext::displaySourceProgress(sysync::TProgressEventEnum type, // because even "good" sources will get a bad status when the overall // session turns bad. We also don't have good explanations for the // status here. - SE_LOG_ERROR(&source, NULL, "%s", Status2String(SyncMLStatus(extra1)).c_str()); + SE_LOG_ERROR(NULL, source.getDisplayName(), "%s", Status2String(SyncMLStatus(extra1)).c_str()); break; } source.recordStatus(SyncMLStatus(extra1)); @@ -4277,7 +4277,7 @@ private: /** capture output produced while test ran */ void messagev(Level level, - const char *prefix, + const std::string *prefix, const char *file, int line, const char *function, diff --git a/src/syncevo/SyncSource.cpp b/src/syncevo/SyncSource.cpp index a073a8a8..888ac457 100644 --- a/src/syncevo/SyncSource.cpp +++ b/src/syncevo/SyncSource.cpp @@ -77,30 +77,12 @@ void SyncSourceBase::throwError(SyncMLStatus status, const string &failure) SyncMLStatus SyncSourceBase::handleException(HandleExceptionFlags flags) { - SyncMLStatus res = Exception::handle(this, flags); + SyncMLStatus res = Exception::handle(getDisplayName(), flags); return res == STATUS_FATAL ? STATUS_DATASTORE_FAILURE : res; } -void SyncSourceBase::messagev(Level level, - const char *prefix, - const char *file, - int line, - const char *function, - const char *format, - va_list args) -{ - string newprefix = getDisplayName(); - if (prefix) { - newprefix += ": "; - newprefix += prefix; - } - LoggerBase::instance().messagev(level, newprefix.c_str(), - file, line, function, - format, args); -} - void SyncSourceBase::getDatastoreXML(string &xml, XMLConfigFragments &fragments) { stringstream xmlstream; @@ -376,7 +358,7 @@ void SyncSource::requestAnotherSync() // stored; instead only a per-session request is set. That's okay // for now because restarting is limited to sessions with only // one source active (intentional simplification). - SE_LOG_DEBUG(this, NULL, "requesting another sync"); + SE_LOG_DEBUG(NULL, getDisplayName(), "requesting another sync"); SyncContext::requestAnotherSync(); } @@ -1265,7 +1247,7 @@ std::string SyncSourceLogging::getDescription(const string &luid) void SyncSourceLogging::insertItemAsKey(sysync::KeyH aItemKey, sysync::ItemID newID) { std::string description = getDescription(aItemKey); - SE_LOG_INFO(this, NULL, + SE_LOG_INFO(NULL, getDisplayName(), description.empty() ? "%s <%s>" : "%s \"%s\"", "adding", !description.empty() ? description.c_str() : "???"); @@ -1274,7 +1256,7 @@ void SyncSourceLogging::insertItemAsKey(sysync::KeyH aItemKey, sysync::ItemID ne void SyncSourceLogging::updateItemAsKey(sysync::KeyH aItemKey, sysync::cItemID aID, sysync::ItemID newID) { std::string description = getDescription(aItemKey); - SE_LOG_INFO(this, NULL, + SE_LOG_INFO(NULL, getDisplayName(), description.empty() ? "%s <%s>" : "%s \"%s\"", "updating", !description.empty() ? description.c_str() : aID ? aID->item : "???"); @@ -1283,7 +1265,7 @@ void SyncSourceLogging::updateItemAsKey(sysync::KeyH aItemKey, sysync::cItemID a void SyncSourceLogging::deleteItem(sysync::cItemID aID) { std::string description = getDescription(aID->item); - SE_LOG_INFO(this, NULL, + SE_LOG_INFO(NULL, getDisplayName(), description.empty() ? "%s <%s>" : "%s \"%s\"", "deleting", !description.empty() ? description.c_str() : aID->item); diff --git a/src/syncevo/SyncSource.h b/src/syncevo/SyncSource.h index c78ecf89..93c01ea7 100644 --- a/src/syncevo/SyncSource.h +++ b/src/syncevo/SyncSource.h @@ -22,7 +22,6 @@ #define INCL_SYNCSOURCE #include <syncevo/SyncConfig.h> -#include <syncevo/Logging.h> #include <syncevo/SyncML.h> #include <syncevo/Timespec.h> @@ -987,7 +986,7 @@ public OperationWrapperSwitch<F, boost::function<F>::arity> * this base via different intermediate classes, therefore the * need to keep it abstract. */ -class SyncSourceBase : public Logger { +class SyncSourceBase { public: virtual ~SyncSourceBase() {} @@ -1097,21 +1096,6 @@ class SyncSourceBase : public Logger { virtual string getNativeDatatypeName(); /** - * Logging utility code. - * - * Every sync source adds "<name>" as prefix to its output. - * All calls are redirected into SyncContext logger. - */ - virtual void messagev(Level level, - const char *prefix, - const char *file, - int line, - const char *function, - const char *format, - va_list args); - virtual bool isProcessSafe() const { return true; } - - /** * return Synthesis API pointer, if one currently is available * (between SyncEvolution_Module_CreateContext() and * SyncEvolution_Module_DeleteContext()) diff --git a/src/syncevo/SynthesisDBPlugin.cpp b/src/syncevo/SynthesisDBPlugin.cpp index 0dccb86a..6e13f2b2 100644 --- a/src/syncevo/SynthesisDBPlugin.cpp +++ b/src/syncevo/SynthesisDBPlugin.cpp @@ -133,7 +133,7 @@ TSyError SyncEvolution_Module_PluginParams( CContext mContext, cAppCharP mConfigParams, CVersion engineVersion ) { SyncSource *source = MoC(mContext); - SE_LOG_DEBUG(source, NULL, "Module_PluginParams\n Engine=%08lX\n %s", + SE_LOG_DEBUG(NULL, source->getDisplayName(), "Module_PluginParams\n Engine=%08lX\n %s", (long)engineVersion, mConfigParams); /*return LOCERR_CFGPARSE;*/ /* if there are unsupported params */ return LOCERR_OK; @@ -399,7 +399,7 @@ TSyError SyncEvolution_CreateContext( CContext *aContext, cAppCharP aContextName *aContext = (CContext)source; err = LOCERR_OK; } - SE_LOG_DEBUG(source, NULL, "'%s' dev='%s' usr='%s' err=%d", + SE_LOG_DEBUG(NULL, source->getDisplayName(), "'%s' dev='%s' usr='%s' err=%d", aContextName, sDevKey, sUsrKey, err); return err; } @@ -413,7 +413,7 @@ uInt32 SyncEvolution_ContextSupport( CContext aContext, cAppCharP aContextRules if (!source) { return LOCERR_WRONGUSAGE; } - SE_LOG_DEBUG(source, NULL, "ContextSupport %s", aContextRules); + SE_LOG_DEBUG(NULL, source->getDisplayName(), "ContextSupport %s", aContextRules); return 0; } @@ -427,7 +427,7 @@ uInt32 SyncEvolution_FilterSupport( CContext aContext, cAppCharP aFilterRules ) if (!source) { return LOCERR_WRONGUSAGE; } - SE_LOG_DEBUG(source, NULL, "FilterSupport %s", aFilterRules); + SE_LOG_DEBUG(NULL, source->getDisplayName(), "FilterSupport %s", aFilterRules); return 0; } /* FilterSupport */ @@ -443,7 +443,7 @@ TSyError SyncEvolution_LoadAdminData( CContext aContext, cAppCharP aLocDB, return LOCERR_WRONGUSAGE; } TSyError res = source->getOperations().m_loadAdminData(*source, aLocDB, aRemDB, adminData); - SE_LOG_DEBUG(source, NULL, "LoadAdminData '%s' '%s', '%s' res=%d", + SE_LOG_DEBUG(NULL, source->getDisplayName(), "LoadAdminData '%s' '%s', '%s' res=%d", aLocDB, aRemDB, *adminData ? *adminData : "", res); return res; } /* LoadAdminData */ @@ -458,7 +458,7 @@ TSyError SyncEvolution_SaveAdminData( CContext aContext, cAppCharP adminData ) return LOCERR_WRONGUSAGE; } TSyError res = source->getOperations().m_saveAdminData(*source, adminData); - SE_LOG_DEBUG(source, NULL, "SaveAdminData '%s' res=%d", adminData, res); + SE_LOG_DEBUG(NULL, source->getDisplayName(), "SaveAdminData '%s' res=%d", adminData, res); return res; } /* SaveAdminData */ @@ -486,7 +486,7 @@ bool SyncEvolution_ReadNextMapItem( CContext aContext, MapID mID, bool aFirst ) res = source->handleException(); } - SE_LOG_DEBUG(source, NULL, "ReadNextMapItem '%s' + %x = '%s' + %d first=%s res=%d", + SE_LOG_DEBUG(NULL, source->getDisplayName(), "ReadNextMapItem '%s' + %x = '%s' + %d first=%s res=%d", res ? NullPtrCheck(mID->localID) : "(none)", res ? mID->ident : 0, res ? NullPtrCheck(mID->remoteID) : "(none)", @@ -506,7 +506,7 @@ TSyError SyncEvolution_InsertMapItem( CContext aContext, cMapID mID ) return LOCERR_WRONGUSAGE; } TSyError res = source->getOperations().m_insertMapItem(*source, mID); - SE_LOG_DEBUG(source, NULL, "InsertMapItem '%s' + %x = '%s' + %x res=%d", + SE_LOG_DEBUG(NULL, source->getDisplayName(), "InsertMapItem '%s' + %x = '%s' + %x res=%d", NullPtrCheck(mID->localID), mID->ident, NullPtrCheck(mID->remoteID), mID->flags, res); @@ -523,7 +523,7 @@ TSyError SyncEvolution_UpdateMapItem( CContext aContext, cMapID mID ) return LOCERR_WRONGUSAGE; } TSyError res = source->getOperations().m_updateMapItem(*source, mID); - SE_LOG_DEBUG(source, NULL, "UpdateMapItem '%s' + %x = '%s' + %x, res=%d", + SE_LOG_DEBUG(NULL, source->getDisplayName(), "UpdateMapItem '%s' + %x = '%s' + %x, res=%d", mID->localID, mID->ident, mID->remoteID, mID->flags, res); @@ -541,7 +541,7 @@ TSyError SyncEvolution_DeleteMapItem( CContext aContext, cMapID mID ) return LOCERR_WRONGUSAGE; } TSyError res = source->getOperations().m_deleteMapItem(*source, mID); - SE_LOG_DEBUG(source, NULL, "DeleteMapItem '%s' + %x = '%s' + %x res=%d", + SE_LOG_DEBUG(NULL, source->getDisplayName(), "DeleteMapItem '%s' + %x = '%s' + %x res=%d", mID->localID, mID->ident, mID->remoteID, mID->flags, res); @@ -596,7 +596,7 @@ TSyError SyncEvolution_AdaptItem( CContext aContext, appCharP *aItemData1, if (!source) { return LOCERR_WRONGUSAGE; } - SE_LOG_DEBUG(source, NULL, "AdaptItem '%s' '%s' '%s' id=%d", + SE_LOG_DEBUG(NULL, source->getDisplayName(), "AdaptItem '%s' '%s' '%s' id=%d", *aItemData1, *aItemData2, *aLocalVars, aIdentifier); return LOCERR_OK; } /* AdaptItem */ @@ -616,7 +616,7 @@ TSyError SyncEvolution_StartDataRead( CContext aContext, cAppCharP lastToken, return LOCERR_WRONGUSAGE; } TSyError res = source->getOperations().m_startDataRead(*source, lastToken, resumeToken); - SE_LOG_DEBUG(source, NULL, "StartDataRead last='%s' resume='%s' res=%d", + SE_LOG_DEBUG(NULL, source->getDisplayName(), "StartDataRead last='%s' resume='%s' res=%d", lastToken, resumeToken, res); return res; } @@ -634,7 +634,7 @@ TSyError SyncEvolution_ReadNextItemAsKey( CContext aContext, ItemID aID, KeyH aI *aStatus = 0; memset(aID, 0, sizeof(*aID)); TSyError res = source->getOperations().m_readNextItem(*source, aID, aStatus, aFirst); - SE_LOG_DEBUG(source, NULL, "ReadNextItemAsKey aStatus=%d aID=(%s,%s) res=%d", + SE_LOG_DEBUG(NULL, source->getDisplayName(), "ReadNextItemAsKey aStatus=%d aID=(%s,%s) res=%d", *aStatus, aID->item, aID->parent, res); return res; } @@ -647,7 +647,7 @@ TSyError SyncEvolution_ReadItemAsKey( CContext aContext, cItemID aID, KeyH aItem return LOCERR_WRONGUSAGE; } TSyError res = source->getOperations().m_readItemAsKey(*source, aID, aItemKey); - SE_LOG_DEBUG(source, NULL, "ReadItemAsKey aID=(%s,%s) res=%d", + SE_LOG_DEBUG(NULL, source->getDisplayName(), "ReadItemAsKey aID=(%s,%s) res=%d", aID->item, aID->parent, res); return res; } @@ -687,7 +687,7 @@ sysync::TSyError SyncEvolution_ReadBlob(CContext aContext, cItemID aID, cAppCh res = LOCERR_NOTIMP; } - SE_LOG_DEBUG(source, NULL, "ReadBlob aID=(%s,%s) aBlobID=(%s) aBlkPtr=%p aBlkSize=%lu aTotSize=%lu aFirst=%s aLast=%s res=%d", + SE_LOG_DEBUG(NULL, source->getDisplayName(), "ReadBlob aID=(%s,%s) aBlobID=(%s) aBlkPtr=%p aBlkSize=%lu aTotSize=%lu aFirst=%s aLast=%s res=%d", aID->item,aID->parent, aBlobID, aBlkPtr, aBlkSize ? (unsigned long)*aBlkSize : 0, aTotSize ? (unsigned long)*aTotSize : 0, @@ -704,7 +704,7 @@ TSyError SyncEvolution_EndDataRead( CContext aContext ) return LOCERR_WRONGUSAGE; } TSyError res = source->getOperations().m_endDataRead(*source); - SE_LOG_DEBUG(source, NULL, "EndDataRead res=%d", res); + SE_LOG_DEBUG(NULL, source->getDisplayName(), "EndDataRead res=%d", res); return res; } @@ -719,7 +719,7 @@ TSyError SyncEvolution_StartDataWrite( CContext aContext ) if (!source) { return LOCERR_WRONGUSAGE; } - SE_LOG_DEBUG(source, NULL, "StartDataWrite"); + SE_LOG_DEBUG(NULL, source->getDisplayName(), "StartDataWrite"); return LOCERR_OK; } @@ -732,7 +732,7 @@ TSyError SyncEvolution_InsertItemAsKey( CContext aContext, KeyH aItemKey, ItemID return LOCERR_WRONGUSAGE; } TSyError res = source->getOperations().m_insertItemAsKey(*source, aItemKey, newID); - SE_LOG_DEBUG(source, NULL, "InsertItemAsKey res=%d\n", res); + SE_LOG_DEBUG(NULL, source->getDisplayName(), "InsertItemAsKey res=%d\n", res); return res; } @@ -746,7 +746,7 @@ TSyError SyncEvolution_UpdateItemAsKey( CContext aContext, KeyH aItemKey, cItemI return LOCERR_WRONGUSAGE; } TSyError res = source->getOperations().m_updateItemAsKey(*source, aItemKey, aID, updID); - SE_LOG_DEBUG(source, NULL, "aID=(%s,%s) res=%d", + SE_LOG_DEBUG(NULL, source->getDisplayName(), "aID=(%s,%s) res=%d", aID->item,aID->parent, res); return res; } @@ -760,7 +760,7 @@ TSyError SyncEvolution_MoveItem( CContext aContext, cItemID aID, cAppCharP newPa if (!source) { return LOCERR_WRONGUSAGE; } - SE_LOG_DEBUG(source, NULL, "MoveItem aID=(%s,%s) => (%s,%s)", + SE_LOG_DEBUG(NULL, source->getDisplayName(), "MoveItem aID=(%s,%s) => (%s,%s)", aID->item,aID->parent, aID->item,newParID); return LOCERR_NOTIMP; } @@ -775,7 +775,7 @@ TSyError SyncEvolution_DeleteItem( CContext aContext, cItemID aID ) return LOCERR_WRONGUSAGE; } TSyError res = source->getOperations().m_deleteItem(*source, aID); - SE_LOG_DEBUG(source, NULL, "DeleteItem aID=(%s,%s) res=%d", + SE_LOG_DEBUG(NULL, source->getDisplayName(), "DeleteItem aID=(%s,%s) res=%d", aID->item, aID->parent, res); return res; } @@ -789,7 +789,7 @@ TSyError SyncEvolution_FinalizeLocalID( CContext aContext, cItemID aID, ItemID u if (!source) { return LOCERR_WRONGUSAGE; } - SE_LOG_DEBUG(source, NULL, "FinalizeLocalID not implemented"); + SE_LOG_DEBUG(NULL, source->getDisplayName(), "FinalizeLocalID not implemented"); return LOCERR_NOTIMP; } @@ -802,7 +802,7 @@ TSyError SyncEvolution_DeleteSyncSet( CContext aContext ) if (!source) { return LOCERR_WRONGUSAGE; } - SE_LOG_DEBUG(source, NULL, "DeleteSyncSet not implemented"); + SE_LOG_DEBUG(NULL, source->getDisplayName(), "DeleteSyncSet not implemented"); return LOCERR_NOTIMP; } @@ -830,7 +830,7 @@ TSyError SyncEvolution_WriteBlob(CContext aContext, cItemID aID, cAppCharP aBlo res = LOCERR_NOTIMP; } - SE_LOG_DEBUG(source, NULL, "WriteBlob aID=(%s,%s) aBlobID=(%s) aBlkPtr=%p aBlkSize=%lu aTotSize=%lu aFirst=%s aLast=%s res=%d", + SE_LOG_DEBUG(NULL, source->getDisplayName(), "WriteBlob aID=(%s,%s) aBlobID=(%s) aBlkPtr=%p aBlkSize=%lu aTotSize=%lu aFirst=%s aLast=%s res=%d", aID->item,aID->parent, aBlobID, aBlkPtr, (unsigned long)aBlkSize, (unsigned long)aTotSize, aFirst ? "true" : "false", aLast ? "true" : "false", res); return res; @@ -846,7 +846,7 @@ TSyError SyncEvolution_DeleteBlob( CContext aContext, cItemID aID, cAppCharP aBl } TSyError res = source->getOperations().m_deleteBlob(*source, aID, aBlobID); - SE_LOG_DEBUG(source, NULL, "DeleteBlob aID=(%s,%s) aBlobID=(%s) res=%d", + SE_LOG_DEBUG(NULL, source->getDisplayName(), "DeleteBlob aID=(%s,%s) aBlobID=(%s) res=%d", aID->item,aID->parent, aBlobID, res); return res; } /* DeleteBlob */ @@ -859,7 +859,7 @@ TSyError SyncEvolution_EndDataWrite( CContext aContext, bool success, appCharP * return LOCERR_WRONGUSAGE; } TSyError res = source->getOperations().m_endDataWrite(*source, success, newToken); - SE_LOG_DEBUG(source, NULL, "EndDataWrite %s '%s' res=%d", + SE_LOG_DEBUG(NULL, source->getDisplayName(), "EndDataWrite %s '%s' res=%d", success ? "COMMIT":"ROLLBACK", *newToken, res); return res; } @@ -873,7 +873,7 @@ TSyError SyncEvolution_DeleteContext( CContext aContext ) if (!source) { return LOCERR_WRONGUSAGE; } - SE_LOG_DEBUG(source, NULL, "DeleteContext"); + SE_LOG_DEBUG(NULL, source->getDisplayName(), "DeleteContext"); source->popSynthesisAPI(); return LOCERR_OK; } diff --git a/src/syncevo/TrackingSyncSource.cpp b/src/syncevo/TrackingSyncSource.cpp index 2d0b35f6..ca8c2951 100644 --- a/src/syncevo/TrackingSyncSource.cpp +++ b/src/syncevo/TrackingSyncSource.cpp @@ -49,16 +49,16 @@ void TrackingSyncSource::checkStatus(SyncSourceReport &changes) string oldRevision = m_metaNode->readProperty("databaseRevision"); if (!oldRevision.empty()) { string newRevision = databaseRevision(); - SE_LOG_DEBUG(this, NULL, "old database revision '%s', new revision '%s'", + SE_LOG_DEBUG(NULL, getDisplayName(), "old database revision '%s', new revision '%s'", oldRevision.c_str(), newRevision.c_str()); if (newRevision == oldRevision) { - SE_LOG_DEBUG(this, NULL, "revisions match, no item changes"); + SE_LOG_DEBUG(NULL, getDisplayName(), "revisions match, no item changes"); mode = CHANGES_NONE; } } if (mode == CHANGES_FULL) { - SE_LOG_DEBUG(this, NULL, "using full item scan to detect changes"); + SE_LOG_DEBUG(NULL, getDisplayName(), "using full item scan to detect changes"); } detectChanges(*m_trackingNode, mode); @@ -86,17 +86,17 @@ void TrackingSyncSource::beginSync(const std::string &lastToken, const std::stri } // slow sync if token is empty if (token.empty()) { - SE_LOG_DEBUG(this, NULL, "slow sync or testing, do full item scan to detect changes"); + SE_LOG_DEBUG(NULL, getDisplayName(), "slow sync or testing, do full item scan to detect changes"); mode = CHANGES_SLOW; } else { string oldRevision = m_metaNode->readProperty("databaseRevision"); if (!oldRevision.empty()) { string newRevision = databaseRevision(); - SE_LOG_DEBUG(this, NULL, "old database revision '%s', new revision '%s'", + SE_LOG_DEBUG(NULL, getDisplayName(), "old database revision '%s', new revision '%s'", oldRevision.c_str(), newRevision.c_str()); if (newRevision == oldRevision) { - SE_LOG_DEBUG(this, NULL, "revisions match, no item changes"); + SE_LOG_DEBUG(NULL, getDisplayName(), "revisions match, no item changes"); mode = CHANGES_NONE; } @@ -107,7 +107,7 @@ void TrackingSyncSource::beginSync(const std::string &lastToken, const std::stri } } if (mode == CHANGES_FULL) { - SE_LOG_DEBUG(this, NULL, "using full item scan to detect changes"); + SE_LOG_DEBUG(NULL, getDisplayName(), "using full item scan to detect changes"); } bool forceSlowSync = detectChanges(*m_trackingNode, mode); diff --git a/src/syncevo/util.cpp b/src/syncevo/util.cpp index 76524a2b..542d26af 100644 --- a/src/syncevo/util.cpp +++ b/src/syncevo/util.cpp @@ -818,7 +818,7 @@ const char * const SYNTHESIS_PROBLEM = "error code from Synthesis engine "; const char * const SYNCEVOLUTION_PROBLEM = "error code from SyncEvolution "; SyncMLStatus Exception::handle(SyncMLStatus *status, - Logger *logger, + const std::string *logPrefix, std::string *explanation, Logger::Level level, HandleExceptionFlags flags) @@ -831,7 +831,7 @@ SyncMLStatus Exception::handle(SyncMLStatus *status, try { throw; } catch (const TransportException &ex) { - SE_LOG_DEBUG(logger, NULL, "TransportException thrown at %s:%d", + SE_LOG_DEBUG(NULL, logPrefix, "TransportException thrown at %s:%d", ex.m_file.c_str(), ex.m_line); error = std::string(TRANSPORT_PROBLEM) + ex.what(); new_status = SyncMLStatus(sysync::LOCERR_TRANSPFAIL); @@ -842,7 +842,7 @@ SyncMLStatus Exception::handle(SyncMLStatus *status, Status2String(new_status).c_str()); } catch (const StatusException &ex) { new_status = ex.syncMLStatus(); - SE_LOG_DEBUG(logger, NULL, "exception thrown at %s:%d", + SE_LOG_DEBUG(NULL, logPrefix, "exception thrown at %s:%d", ex.m_file.c_str(), ex.m_line); error = StringPrintf("%s%s: %s", SYNCEVOLUTION_PROBLEM, @@ -852,7 +852,7 @@ SyncMLStatus Exception::handle(SyncMLStatus *status, level = Logger::DEBUG; } } catch (const Exception &ex) { - SE_LOG_DEBUG(logger, NULL, "exception thrown at %s:%d", + SE_LOG_DEBUG(NULL, logPrefix, "exception thrown at %s:%d", ex.m_file.c_str(), ex.m_line); error = ex.what(); } catch (const std::exception &ex) { @@ -866,7 +866,7 @@ SyncMLStatus Exception::handle(SyncMLStatus *status, if (flags & HANDLE_EXCEPTION_NO_ERROR) { level = Logger::DEBUG; } - SE_LOG(level, logger, NULL, "%s", error.c_str()); + SE_LOG(level, NULL, logPrefix, "%s", error.c_str()); if (flags & HANDLE_EXCEPTION_FATAL) { // Something unexpected went wrong, can only shut down. ::abort(); diff --git a/src/syncevo/util.h b/src/syncevo/util.h index 96f1444a..f224d8c8 100644 --- a/src/syncevo/util.h +++ b/src/syncevo/util.h @@ -22,6 +22,7 @@ # define INCL_SYNCEVOLUTION_UTIL #include <syncevo/SyncML.h> +#include <syncevo/Logging.h> #include <boost/algorithm/string/case_conv.hpp> #include <boost/algorithm/string/predicate.hpp> @@ -40,13 +41,10 @@ #include <syncevo/Timespec.h> // definitions used to be included in util.h, // include it to avoid changing code using the time things -#include <syncevo/Logging.h> #include <syncevo/declarations.h> SE_BEGIN_CXX -class Logger; - /** case-insensitive less than for assoziative containers */ template <class T> class Nocase : public std::binary_function<T, T, bool> { public: @@ -521,12 +519,12 @@ class Exception : public std::runtime_error * status code if status still was STATUS_OK when called. * Returns updated status code. * - * @param logger the class which does the logging + * @param logPrefix passed to SE_LOG* messages * @retval explanation set to explanation for problem, if non-NULL * @param level level to be used for logging */ - static SyncMLStatus handle(SyncMLStatus *status = NULL, Logger *logger = NULL, std::string *explanation = NULL, Logger::Level = Logger::ERROR, HandleExceptionFlags flags = HANDLE_EXCEPTION_FLAGS_NONE); - static SyncMLStatus handle(Logger *logger, HandleExceptionFlags flags = HANDLE_EXCEPTION_FLAGS_NONE) { return handle(NULL, logger, NULL, Logger::ERROR, flags); } + static SyncMLStatus handle(SyncMLStatus *status = NULL, const std::string *logPrefix = NULL, std::string *explanation = NULL, Logger::Level = Logger::ERROR, HandleExceptionFlags flags = HANDLE_EXCEPTION_FLAGS_NONE); + static SyncMLStatus handle(const std::string &logPrefix, HandleExceptionFlags flags = HANDLE_EXCEPTION_FLAGS_NONE) { return handle(NULL, &logPrefix, NULL, Logger::ERROR, flags); } static SyncMLStatus handle(std::string &explanation, HandleExceptionFlags flags = HANDLE_EXCEPTION_FLAGS_NONE) { return handle(NULL, NULL, &explanation, Logger::ERROR, flags); } static void handle(HandleExceptionFlags flags) { handle(NULL, NULL, NULL, Logger::ERROR, flags); } static void log() { handle(NULL, NULL, NULL, Logger::DEBUG); } |