[geary/wip/problem-report-logs: 3/22] Convert key classes to implement Loggable



commit 981edfd071903c02df8eeebd85ea7780b871a278
Author: Michael Gratton <mike vee net>
Date:   Sat Dec 29 13:34:29 2018 +1100

    Convert key classes to implement Loggable
    
    Make accounts, folders, client sessions and account ops implement
    Loggable, remove manual context from log messages there and in
    subclasses.

 src/engine/api/geary-account.vala                  | 24 +++---
 src/engine/api/geary-client-service.vala           | 38 ++++++---
 src/engine/api/geary-folder.vala                   | 22 +++--
 .../gmail/imap-engine-gmail-folder.vala            |  4 +-
 .../imap-engine/imap-engine-account-operation.vala | 18 ++--
 .../imap-engine/imap-engine-generic-account.vala   | 62 +++++++-------
 .../imap-engine/imap-engine-minimal-folder.vala    | 97 +++++++++++-----------
 src/engine/imap/api/imap-client-service.vala       | 47 +++++------
 src/engine/imap/transport/imap-deserializer.vala   |  6 +-
 9 files changed, 171 insertions(+), 147 deletions(-)
---
diff --git a/src/engine/api/geary-account.vala b/src/engine/api/geary-account.vala
index b0edd857..ad368170 100644
--- a/src/engine/api/geary-account.vala
+++ b/src/engine/api/geary-account.vala
@@ -22,7 +22,7 @@
  * A list of all Accounts may be retrieved from the {@link Engine} singleton.
  */
 
-public abstract class Geary.Account : BaseObject {
+public abstract class Geary.Account : BaseObject, Loggable {
 
 
     /** Number of times to attempt re-authentication. */
@@ -137,8 +137,6 @@ public abstract class Geary.Account : BaseObject {
     public Geary.ProgressMonitor opening_monitor { get; protected set; }
     public Geary.ProgressMonitor sending_monitor { get; protected set; }
 
-    protected string id { get; private set; }
-
 
     public signal void opened();
 
@@ -250,6 +248,14 @@ public abstract class Geary.Account : BaseObject {
     public signal void email_flags_changed(Geary.Folder folder,
         Gee.Map<Geary.EmailIdentifier, Geary.EmailFlags> map);
 
+    /** {@inheritDoc} */
+    public Logging.Flag loggable_flags {
+        get; protected set; default = Logging.Flag.ALL;
+    }
+
+    /** {@inheritDoc} */
+    public Loggable? loggable_parent { get { return null; } }
+
 
     protected Account(AccountInformation information,
                       ClientService incoming,
@@ -257,9 +263,6 @@ public abstract class Geary.Account : BaseObject {
         this.information = information;
         this.incoming = incoming;
         this.outgoing = outgoing;
-        this.id = "%s[%s]".printf(
-            information.id, information.service_provider.to_value()
-        );
 
         incoming.notify["current-status"].connect(
             on_service_status_notify
@@ -484,11 +487,12 @@ public abstract class Geary.Account : BaseObject {
     public abstract async Gee.MultiMap<Geary.EmailIdentifier, Geary.FolderPath>? 
get_containing_folders_async(
         Gee.Collection<Geary.EmailIdentifier> ids, Cancellable? cancellable) throws Error;
 
-    /**
-     * Used only for debugging.  Should not be used for user-visible strings.
-     */
+    /** {@inheritDoc} */
     public virtual string to_string() {
-        return this.id;
+        return "%s(%s)".printf(
+            this.get_type().name(),
+            this.information.id
+        );
     }
 
     /** Fires a {@link opened} signal. */
diff --git a/src/engine/api/geary-client-service.vala b/src/engine/api/geary-client-service.vala
index 4fbae488..6f6da006 100644
--- a/src/engine/api/geary-client-service.vala
+++ b/src/engine/api/geary-client-service.vala
@@ -14,7 +14,7 @@
  * itself, rather manages the configuration, status tracking, and
  * life-cycle of concrete implementations.
  */
-public abstract class Geary.ClientService : BaseObject {
+public abstract class Geary.ClientService : BaseObject, Loggable {
 
 
     private const int BECAME_REACHABLE_TIMEOUT_SEC = 1;
@@ -197,6 +197,15 @@ public abstract class Geary.ClientService : BaseObject {
     /** The last reported error, if any. */
     public ErrorContext? last_error { get; private set; default = null; }
 
+    /** {@inheritDoc} */
+    public Logging.Flag loggable_flags {
+        get; protected set; default = Logging.Flag.ALL;
+    }
+
+    /** {@inheritDoc} */
+    public Loggable? loggable_parent { get { return _loggable_parent; } }
+    private weak Loggable? _loggable_parent = null;
+
 
     protected ClientService(AccountInformation account,
                             ServiceInformation configuration,
@@ -283,6 +292,19 @@ public abstract class Geary.ClientService : BaseObject {
         yield start(cancellable);
     }
 
+    /** {@inheritDoc} */
+    public virtual string to_string() {
+        return "%s(%s)".printf(
+            this.get_type().name(),
+            this.configuration.protocol.to_value()
+        );
+    }
+
+    /** Sets the service's logging parent. */
+    internal void set_loggable_parent(Loggable parent) {
+        this._loggable_parent = parent;
+    }
+
     /**
      * Called when the network service has become reachable.
      *
@@ -407,21 +429,11 @@ public abstract class Geary.ClientService : BaseObject {
     }
 
     private void on_running_notify() {
-        debug(
-            "%s:%s %s",
-            this.account.id,
-            this.configuration.protocol.to_value(),
-            this.is_running ? "started" : "stopped"
-        );
+        debug(this.is_running ? "Started" : "Stopped");
     }
 
     private void on_current_status_notify() {
-        debug(
-            "%s:%s: status changed to: %s",
-            this.account.id,
-            this.configuration.protocol.to_value(),
-            this.current_status.to_value()
-        );
+        debug("Status changed to: %s", this.current_status.to_value());
     }
 
     private void on_connectivity_change() {
diff --git a/src/engine/api/geary-folder.vala b/src/engine/api/geary-folder.vala
index b6f57fc8..948b925f 100644
--- a/src/engine/api/geary-folder.vala
+++ b/src/engine/api/geary-folder.vala
@@ -61,7 +61,7 @@
  *
  * @see Geary.SpecialFolderType
  */
-public abstract class Geary.Folder : BaseObject {
+public abstract class Geary.Folder : BaseObject, Loggable {
 
     /**
      * Indicates if a folder has been opened, and if so in which way.
@@ -238,6 +238,15 @@ public abstract class Geary.Folder : BaseObject {
     /** Monitor for notifying of progress when opening the folder. */
     public abstract Geary.ProgressMonitor opening_monitor { get; }
 
+    /** {@inheritDoc} */
+    public Logging.Flag loggable_flags {
+        get; protected set; default = Logging.Flag.ALL;
+    }
+
+    /** {@inheritDoc} */
+    public Loggable? loggable_parent {
+        get { return this.account; }
+    }
 
     /**
      * Fired when the folder moves through stages of being opened.
@@ -673,10 +682,13 @@ public abstract class Geary.Folder : BaseObject {
     public abstract async Geary.Email fetch_email_async(Geary.EmailIdentifier email_id,
         Geary.Email.Field required_fields, ListFlags flags, Cancellable? cancellable = null) throws Error;
 
-    /**
-     * Used for debugging.  Should not be used for user-visible labels.
-     */
+    /** {@inheritDoc} */
     public virtual string to_string() {
-        return "%s:%s".printf(this.account.information.id, this.path.to_string());
+        return "%s(%s:%s)".printf(
+            this.get_type().name(),
+            this.account.information.id,
+            this.path.to_string()
+        );
     }
+
 }
diff --git a/src/engine/imap-engine/gmail/imap-engine-gmail-folder.vala 
b/src/engine/imap-engine/gmail/imap-engine-gmail-folder.vala
index bddcb9d9..4744f67c 100644
--- a/src/engine/imap-engine/gmail/imap-engine-gmail-folder.vala
+++ b/src/engine/imap-engine/gmail/imap-engine-gmail-folder.vala
@@ -68,7 +68,7 @@ private class Geary.ImapEngine.GmailFolder : MinimalFolder, FolderSupport.Archiv
         // messages are removed from all labels)
         Gee.Set<Imap.UID>? uids = yield folder.copy_email_uids_async(email_ids, trash.path, cancellable);
         if (uids == null || uids.size == 0) {
-            debug("%s: Can't true-remove %d emails, no COPYUIDs returned", folder.to_string(),
+            GLib.debug("%s: Can't true-remove %d emails, no COPYUIDs returned", folder.to_string(),
                 email_ids.size);
 
             return;
@@ -87,7 +87,7 @@ private class Geary.ImapEngine.GmailFolder : MinimalFolder, FolderSupport.Archiv
             yield account.release_folder_session(imap_trash);
         }
 
-        debug("%s: Successfully true-removed %d/%d emails", folder.to_string(), uids.size,
+        GLib.debug("%s: Successfully true-removed %d/%d emails", folder.to_string(), uids.size,
             email_ids.size);
     }
 }
diff --git a/src/engine/imap-engine/imap-engine-account-operation.vala 
b/src/engine/imap-engine/imap-engine-account-operation.vala
index ea9641b0..99a7fdb3 100644
--- a/src/engine/imap-engine/imap-engine-account-operation.vala
+++ b/src/engine/imap-engine/imap-engine-account-operation.vala
@@ -33,9 +33,17 @@
  * equal_to} method to specify which instances are considered to be
  * duplicates.
  */
-public abstract class Geary.ImapEngine.AccountOperation : Geary.BaseObject {
+public abstract class Geary.ImapEngine.AccountOperation : BaseObject, Loggable {
 
 
+    /** {@inheritDoc} */
+    public Logging.Flag loggable_flags {
+        get; protected set; default = Logging.Flag.ALL;
+    }
+
+    /** {@inheritDoc} */
+    public Loggable? loggable_parent { get { return account; } }
+
     /** The account this operation applies to. */
     protected weak Geary.Account account { get; private set; }
 
@@ -103,13 +111,9 @@ public abstract class Geary.ImapEngine.AccountOperation : Geary.BaseObject {
         return (op != null && (this == op || this.get_type() == op.get_type()));
     }
 
-    /**
-     * Provides a representation of this operation for debugging.
-     *
-     * By default simply returns the name of the class.
-     */
+    /** {@inheritDoc} */
     public virtual string to_string() {
-        return this.get_type().name();
+        return get_type().name();
     }
 
 }
diff --git a/src/engine/imap-engine/imap-engine-generic-account.vala 
b/src/engine/imap-engine/imap-engine-generic-account.vala
index 719142f4..e734868f 100644
--- a/src/engine/imap-engine/imap-engine-generic-account.vala
+++ b/src/engine/imap-engine/imap-engine-generic-account.vala
@@ -89,11 +89,13 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
         imap.notify["current-status"].connect(
             on_imap_status_notify
         );
+        imap.set_loggable_parent(this);
         this.imap = imap;
 
         smtp.outbox = new Outbox.Folder(this, local_folder_root, local);
         smtp.email_sent.connect(on_email_sent);
         smtp.report_problem.connect(notify_report_problem);
+        smtp.set_loggable_parent(this);
         this.smtp = smtp;
 
         this.sync = new AccountSynchronizer(this);
@@ -192,9 +194,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
         try {
             yield this.smtp.stop();
         } catch (Error err) {
-            debug(
-                "%s: Error stopping SMTP service: %s", to_string(), err.message
-            );
+            debug("Error stopping SMTP service: %s", err.message);
         }
 
         // Halt internal tasks early so they stop using local and
@@ -221,11 +221,11 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
         notify_folders_available_unavailable(null, remotes);
 
         foreach (Geary.Folder folder in locals) {
-            debug("%s: Waiting for local to close: %s", to_string(), folder.to_string());
+            debug("Waiting for local to close: %s", folder.to_string());
             yield folder.wait_for_close_async();
         }
         foreach (Geary.Folder folder in remotes) {
-            debug("%s: Waiting for remote to close: %s", to_string(), folder.to_string());
+            debug("Waiting for remote to close: %s", folder.to_string());
             yield folder.wait_for_close_async();
         }
 
@@ -234,9 +234,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
         try {
             yield this.imap.stop();
         } catch (Error err) {
-            debug(
-                "%s: Error stopping IMAP service: %s", to_string(), err.message
-            );
+            debug("Error stopping IMAP service: %s", err.message);
         }
         this.remote_ready_lock = null;
 
@@ -264,9 +262,9 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
             );
         }
 
-        message("%s: Rebuilding account local data", to_string());
+        message("Rebuilding account local data");
         yield this.local.delete_all_data(cancellable);
-        message("%s: Rebuild complete", to_string());
+        message("Rebuild complete");
     }
 
     /**
@@ -279,7 +277,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
     public void queue_operation(AccountOperation op)
         throws EngineError {
         check_open();
-        debug("%s: Enqueuing operation: %s", this.to_string(), op.to_string());
+        debug("Enqueuing operation: %s", op.to_string());
         this.processor.enqueue(op);
     }
 
@@ -297,7 +295,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
     public async Imap.AccountSession claim_account_session(Cancellable? cancellable = null)
         throws Error {
         check_open();
-        debug("%s: Acquiring account session", this.to_string());
+        debug("Acquiring account session");
         yield this.remote_ready_lock.wait_async(cancellable);
         Imap.ClientSession client =
             yield this.imap.claim_authorized_session_async(cancellable);
@@ -310,7 +308,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
      * Returns an IMAP account session to the pool for re-use.
      */
     public void release_account_session(Imap.AccountSession session) {
-        debug("%s: Releasing account session", this.to_string());
+        debug("Releasing account session");
         Imap.ClientSession? old_session = session.close();
         if (old_session != null) {
             this.imap.release_session_async.begin(
@@ -319,9 +317,9 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
                     try {
                         this.imap.release_session_async.end(res);
                     } catch (Error err) {
-                        debug("%s: Error releasing account session: %s",
-                              to_string(),
-                              err.message);
+                        debug(
+                            "Error releasing account session: %s", err.message
+                        );
                     }
                 }
             );
@@ -343,7 +341,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
                                                          Cancellable cancellable)
         throws Error {
         check_open();
-        debug("%s: Acquiring folder session", this.to_string());
+        debug("Acquiring folder session for: %s", path.to_string());
         yield this.remote_ready_lock.wait_async(cancellable);
 
         // We manually construct an account session here and then
@@ -394,14 +392,13 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
      * Returns an IMAP folder session to the pool for cleanup and re-use.
      */
     public async void release_folder_session(Imap.FolderSession session) {
-        debug("%s: Releasing folder session", this.to_string());
+        debug("Releasing folder session");
         Imap.ClientSession? old_session = session.close();
         if (old_session != null) {
             try {
                 yield this.imap.release_session_async(old_session);
             } catch (Error err) {
-                debug("%s: Error releasing %s session: %s",
-                      to_string(),
+                debug("Error releasing %s session: %s",
                       session.folder.path.to_string(),
                       err.message);
             }
@@ -623,7 +620,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
         Gee.Collection<Geary.Folder> folders =
             new Gee.LinkedList<Geary.Folder>();
         folders.add(folder);
-        debug("Contents altered!");
+        debug("Folder updated: %s", folder.path.to_string());
         notify_folders_contents_altered(folders);
     }
 
@@ -646,8 +643,8 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
         foreach (Geary.SpecialFolderType special in specials.keys) {
             MinimalFolder? minimal = specials.get(special) as MinimalFolder;
             if (minimal.special_folder_type != special) {
-                debug("%s: Promoting %s to %s",
-                      to_string(), minimal.to_string(), special.to_string());
+                debug("Promoting %s to %s",
+                      minimal.to_string(), special.to_string());
                 minimal.set_special_folder_type(special);
                 changed.add(minimal);
 
@@ -655,8 +652,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
                 try {
                     existing = get_special_folder(special) as MinimalFolder;
                 } catch (Error err) {
-                    debug("%s: Error getting special folder: %s",
-                          to_string(), err.message);
+                    debug("Error getting special folder: %s", err.message);
                 }
 
                 if (existing != null && existing != minimal) {
@@ -716,8 +712,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
             if (path != null) {
                 if (!remote.is_folder_path_valid(path)) {
                     warning(
-                        "%s: Ignoring bad special folder path '%s' for type %s",
-                        to_string(),
+                        "Ignoring bad special folder path '%s' for type %s",
                         path.to_string(),
                         type.to_string()
                     );
@@ -747,15 +742,15 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
                     path = root.get_child(search_names[0]);
                 }
 
-                debug("%s: Guessed folder \'%s\' for special_path %s",
-                      to_string(), path.to_string(), type.to_string()
+                debug("Guessed folder \'%s\' for special_path %s",
+                      path.to_string(), type.to_string()
                 );
                 information.set_special_folder_path(type, path);
             }
 
             if (!this.folder_map.has_key(path)) {
-                debug("%s: Creating \"%s\" to use as special folder %s",
-                      to_string(), path.to_string(), type.to_string());
+                debug("Creating \"%s\" to use as special folder %s",
+                      path.to_string(), type.to_string());
 
                 GLib.Error? created_err = null;
                 try {
@@ -1117,8 +1112,7 @@ internal class Geary.ImapEngine.LoadFolders : AccountOperation {
                         added_specials.set(type, target);
                     } catch (Error err) {
                         debug(
-                            "%s: Previously used special folder %s not loaded: %s",
-                            generic.information.id,
+                            "Previously used special folder %s not loaded: %s",
                             type.to_string(),
                             err.message
                         );
@@ -1224,7 +1218,7 @@ internal class Geary.ImapEngine.UpdateRemoteFolders : AccountOperation {
             if (err is IOError || err is ImapError)
                 throw err;
             debug("Ignoring error listing child folders of %s: %s",
-                (parent != null ? parent.to_string() : "root"), err.message);
+                  (parent != null ? parent.to_string() : "root"), err.message);
             results_suspect = true;
         }
 
diff --git a/src/engine/imap-engine/imap-engine-minimal-folder.vala 
b/src/engine/imap-engine/imap-engine-minimal-folder.vala
index f1c2c80b..b450f4ec 100644
--- a/src/engine/imap-engine/imap-engine-minimal-folder.vala
+++ b/src/engine/imap-engine/imap-engine-minimal-folder.vala
@@ -239,7 +239,7 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
     public async Imap.FolderSession claim_remote_session(Cancellable? cancellable = null)
         throws Error {
         check_open("claim_remote_session");
-        debug("%s: Claiming folder session", this.to_string());
+        debug("Claiming folder session");
 
 
         // If remote has not yet been opened and we are not in the
@@ -258,7 +258,7 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
     public override async bool close_async(Cancellable? cancellable = null)
         throws Error {
         check_open("close_async");
-        debug("%s: Scheduling folder close", this.to_string());
+        debug("Scheduling folder close");
         // Although it's inefficient in the case of just decrementing
         // the open count, pass all requests to close via the replay
         // queue so that other operations queued are interleaved in an
@@ -302,7 +302,7 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
     private async void normalize_folders(Geary.Imap.FolderSession session,
                                          Cancellable cancellable)
         throws Error {
-        debug("%s: Begin normalizing remote and local folders", to_string());
+        debug("Begin normalizing remote and local folders");
 
         Geary.Imap.FolderProperties local_properties = this.local_folder.get_properties();
         Geary.Imap.FolderProperties remote_properties = session.folder.properties;
@@ -341,7 +341,7 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
         //
         // see http://tools.ietf.org/html/rfc3501#section-2.3.1.1
         if (local_properties.uid_validity.value != remote_properties.uid_validity.value) {
-            debug("%s: UID validity changed, detaching all email: %s -> %s", to_string(),
+            debug("UID validity changed, detaching all email: %s -> %s",
                 local_properties.uid_validity.value.to_string(),
                 remote_properties.uid_validity.value.to_string());
             yield detach_all_emails_async(cancellable);
@@ -366,7 +366,7 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
 
         // if no earliest UID, that means no messages in local store, so nothing to update
         if (local_earliest_id == null || local_latest_id == null) {
-            debug("%s: local store empty, nothing to normalize", to_string());
+            debug("local store empty, nothing to normalize");
             return;
         }
 
@@ -387,7 +387,8 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
 
         bool is_dirty = (already_marked_ids != null && already_marked_ids.size > 0);
         if (is_dirty)
-            debug("%s: %d remove markers found, folder is dirty", to_string(), already_marked_ids.size);
+            debug("%d remove markers found, folder is dirty",
+                  already_marked_ids.size);
 
         // a full normalize works from the highest possible UID on the remote and work down to the lowest 
UID on
         // the local; this covers all messages appended since last seen as well as any removed
@@ -396,9 +397,10 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
         // if either local UID is out of range of the current highest UID, then something very wrong
         // has occurred; the only recourse is to wipe all associations and start over
         if (local_earliest_id.uid.compare_to(last_uid) > 0 || local_latest_id.uid.compare_to(last_uid) > 0) {
-            debug("%s: Local UID(s) higher than remote UIDNEXT, detaching all email: %s/%s remote=%s",
-                to_string(), local_earliest_id.uid.to_string(), local_latest_id.uid.to_string(),
-                last_uid.to_string());
+            debug("Local UID(s) higher than remote UIDNEXT, detaching all email: %s/%s remote=%s",
+                  local_earliest_id.uid.to_string(),
+                  local_latest_id.uid.to_string(),
+                  last_uid.to_string());
             yield detach_all_emails_async(cancellable);
             return;
         }
@@ -419,7 +421,7 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
         // email is the same, then nothing has been added or removed,
         // and we're done.
         if (!is_dirty && uidnext_diff == 0 && local_message_count == remote_message_count) {
-            debug("%s: No messages added/removed since last opened, normalization completed", to_string());
+            debug("No messages added/removed since last opened, normalization completed");
             return;
         }
 
@@ -434,15 +436,15 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
         if (!is_dirty && uidnext_diff == (remote_message_count - local_message_count)) {
             first_uid = local_latest_id.uid.next(true);
 
-            debug("%s: Messages only appended (local/remote UIDNEXT=%s/%s total=%d/%d diff=%s), gathering 
mail UIDs %s:%s",
-                to_string(), local_properties.uid_next.to_string(), remote_properties.uid_next.to_string(),
+            debug("Messages only appended (local/remote UIDNEXT=%s/%s total=%d/%d diff=%s), gathering mail 
UIDs %s:%s",
+                local_properties.uid_next.to_string(), remote_properties.uid_next.to_string(),
                 local_properties.select_examine_messages, remote_properties.select_examine_messages, 
uidnext_diff.to_string(),
                 first_uid.to_string(), last_uid.to_string());
         } else {
             first_uid = local_earliest_id.uid;
 
-            debug("%s: Messages appended/removed (local/remote UIDNEXT=%s/%s total=%d/%d diff=%s), gathering 
mail UIDs %s:%s",
-                to_string(), local_properties.uid_next.to_string(), remote_properties.uid_next.to_string(),
+            debug("Messages appended/removed (local/remote UIDNEXT=%s/%s total=%d/%d diff=%s), gathering 
mail UIDs %s:%s",
+                local_properties.uid_next.to_string(), remote_properties.uid_next.to_string(),
                 local_properties.select_examine_messages, remote_properties.select_examine_messages, 
uidnext_diff.to_string(),
                 first_uid.to_string(), last_uid.to_string());
         }
@@ -464,8 +466,8 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
 
         check_open("normalize_folders (list remote)");
 
-        debug("%s: Loaded local (%d) and remote (%d) UIDs, normalizing...", to_string(),
-            local_uids.size, remote_uids.size);
+        debug("Loaded local (%d) and remote (%d) UIDs, normalizing...",
+              local_uids.size, remote_uids.size);
 
         Gee.HashSet<Imap.UID> removed_uids = new Gee.HashSet<Imap.UID>();
         Gee.HashSet<Imap.UID> appended_uids = new Gee.HashSet<Imap.UID>();
@@ -503,8 +505,8 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
             }
         }, cancellable);
 
-        debug("%s: changes since last seen: removed=%d appended=%d inserted=%d", to_string(),
-            removed_uids.size, appended_uids.size, inserted_uids.size);
+        debug("Changes since last seen: removed=%d appended=%d inserted=%d",
+              removed_uids.size, appended_uids.size, inserted_uids.size);
 
         /*
          * Step 4: Synchronise local folder with remote
@@ -565,7 +567,7 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
                 }
             }, cancellable);
 
-            debug("%s: Finished creating/merging %d emails", to_string(), created_or_merged.size);
+            debug("Finished creating/merging %d emails", created_or_merged.size);
         }
 
         check_open("normalize_folders (created/merged appended/inserted emails)");
@@ -603,7 +605,8 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
             replay_queue.notify_remote_removed_ids(removed_ids);
 
             // notify subscribers about emails that have been removed
-            debug("%s: Notifying of %d removed emails since last opened", to_string(), removed_ids.size);
+            debug("Notifying of %d removed emails since last opened",
+                  removed_ids.size);
             notify_email_removed(removed_ids);
 
             count_change_reason |= Folder.CountChangeReason.REMOVED;
@@ -611,7 +614,8 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
 
         // notify inserted (new email located somewhere inside the local vector)
         if (inserted_ids.size > 0) {
-            debug("%s: Notifying of %d inserted emails since last opened", to_string(), inserted_ids.size);
+            debug("Notifying of %d inserted emails since last opened",
+                  inserted_ids.size);
             notify_email_inserted(inserted_ids);
 
             count_change_reason |= Folder.CountChangeReason.INSERTED;
@@ -620,8 +624,8 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
         // notify inserted (new email located somewhere inside the local vector that had to be
         // created, i.e. no portion was stored locally)
         if (locally_inserted_ids.size > 0) {
-            debug("%s: Notifying of %d locally inserted emails since last opened", to_string(),
-                locally_inserted_ids.size);
+            debug("Notifying of %d locally inserted emails since last opened",
+                  locally_inserted_ids.size);
             notify_email_locally_inserted(locally_inserted_ids);
 
             count_change_reason |= Folder.CountChangeReason.INSERTED;
@@ -629,29 +633,30 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
 
         // notify appended (new email added since the folder was last opened)
         if (appended_ids.size > 0) {
-            debug("%s: Notifying of %d appended emails since last opened", to_string(), appended_ids.size);
+            debug("Notifying of %d appended emails since last opened",
+                  appended_ids.size);
             notify_email_appended(appended_ids);
 
             count_change_reason |= Folder.CountChangeReason.APPENDED;
         }
 
-        // notify locally appended (new email never seen before added since the folder was last
-        // opened)
+        // notify locally appended (new email never seen before added
+        // since the folder was last opened)
         if (locally_appended_ids.size > 0) {
-            debug("%s: Notifying of %d locally appended emails since last opened", to_string(),
-                locally_appended_ids.size);
+            debug("Notifying of %d locally appended emails since last opened",
+                  locally_appended_ids.size);
             notify_email_locally_appended(locally_appended_ids);
 
             count_change_reason |= Folder.CountChangeReason.APPENDED;
         }
 
         if (count_change_reason != Folder.CountChangeReason.NONE) {
-            debug("%s: Notifying of %Xh count change reason (%d remote messages)", to_string(),
-                count_change_reason, remote_message_count);
+            debug("Notifying of %Xh count change reason (%d remote messages)",
+                  count_change_reason, remote_message_count);
             notify_email_count_changed(remote_message_count, count_change_reason);
         }
 
-        debug("%s: Completed normalize_folder", to_string());
+        debug("Completed normalize_folder");
     }
 
     /**
@@ -798,7 +803,7 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
             this.remote_open_timer.start();
         }
 
-        debug("%s: Folder opened", to_string());
+        debug("Folder opened");
         return true;
     }
 
@@ -828,7 +833,7 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
     private async void close_internal_locked(Folder.CloseReason local_reason,
                                              Folder.CloseReason remote_reason,
                                              Cancellable? cancellable) {
-        debug("%s: Folder closing", to_string());
+        debug("Folder closing");
 
         // Ensure we don't attempt to start opening a remote while
         // closing
@@ -872,15 +877,13 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
         // Close the replay queues; if a "clean" close, flush pending
         // operations so everything gets a chance to run; if forced
         // close, drop everything outstanding
-        debug("Closing replay queue for %s (flush_pending=%s): %s",
-              to_string(), flush_pending.to_string(), this.replay_queue.to_string());
+        debug("Closing replay queue for (flush_pending=%s): %s",
+              flush_pending.to_string(), this.replay_queue.to_string());
         try {
             yield this.replay_queue.close_async(flush_pending);
-            debug("Closed replay queue for %s: %s",
-                  to_string(), this.replay_queue.to_string());
+            debug("Closed replay queue: %s", this.replay_queue.to_string());
         } catch (Error err) {
-            debug("Error closing %s replay queue: %s",
-                  to_string(), err.message);
+            warning("Error closing replay queue: %s", err.message);
         }
 
         // Actually close the remote folder
@@ -905,7 +908,7 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
         // Notify waiting tasks
         this.closed_semaphore.blind_notify();
 
-        debug("%s: Folder closed", to_string());
+        debug("Folder closed");
     }
 
     /**
@@ -934,7 +937,7 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
 
     // Should only be called when remote_mutex is locked, i.e. use open_remote_session()
     private async void open_remote_session_locked(Cancellable? cancellable) {
-        debug("%s: Opening remote session", to_string());
+        debug("Opening remote session");
 
         // Note that any IOError.CANCELLED errors caught below do not
         // cause any error signals to be fired and do not force
@@ -1080,8 +1083,8 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
         // Use the session param rather than remote_session attr since
         // it may not be available yet
         int remote_count = session.folder.properties.email_total;
-        debug("%s on_remote_appended: remote_count=%d appended=%d",
-              to_string(), remote_count, appended);
+        debug("on_remote_appended: remote_count=%d appended=%d",
+              remote_count, appended);
 
         // from the new remote total and the old remote total, glean the SequenceNumbers of the
         // new email(s)
@@ -1106,7 +1109,7 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
         // Use the session param rather than remote_session attr since
         // it may not be available yet
         int remote_count = session.folder.properties.email_total;
-        debug("%s on_remote_updated: remote_count=%d position=%s", to_string(),
+        debug("on_remote_updated: remote_count=%d position=%s",
               remote_count, position.to_string());
 
         this.replay_queue.schedule_server_notification(
@@ -1119,8 +1122,8 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
         // Use the session param rather than remote_session attr since
         // it may not be available yet
         int remote_count = session.folder.properties.email_total;
-        debug("%s on_remote_removed: remote_count=%d position=%s",
-              to_string(), remote_count, position.to_string());
+        debug("on_remote_removed: remote_count=%d position=%s",
+              remote_count, position.to_string());
 
         // notify of removal to all pending replay operations
         replay_queue.notify_remote_removed_position(position);
@@ -1490,7 +1493,7 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
 
             // Fetch e-mail from folder using force update, which will cause the cache to be bypassed
             // and the latest to be gotten from the server (updating the cache in the process)
-            debug("%s: fetching %d flags", this.to_string(), local_map.keys.size);
+            debug("Fetching %d flags", local_map.keys.size);
             Gee.List<Geary.Email>? list_remote = yield list_email_by_sparse_id_async(
                 local_map.keys,
                 Email.Field.FLAGS,
diff --git a/src/engine/imap/api/imap-client-service.vala b/src/engine/imap/api/imap-client-service.vala
index 24a1d0d2..f07a2379 100644
--- a/src/engine/imap/api/imap-client-service.vala
+++ b/src/engine/imap/api/imap-client-service.vala
@@ -131,8 +131,7 @@ internal class Geary.Imap.ClientService : Geary.ClientService {
         // this, but it's easy and works for now
         int attempts = 0;
         while (this.all_sessions.size > 0) {
-            debug("[%s] Waiting for client sessions to disconnect...",
-                  this.account.id);
+            debug("Waiting for client sessions to disconnect...");
             Timeout.add(250, this.stop.callback);
             yield;
 
@@ -208,8 +207,8 @@ internal class Geary.Imap.ClientService : Geary.ClientService {
         // Don't check_open(), it's valid for this to be called when
         // is_running is false, that happens during mop-up
 
-        debug("[%s] Returning session with %d of %d free",
-              this.account.id, this.free_queue.size, this.all_sessions.size);
+        debug("Returning session with %d of %d free",
+              this.free_queue.size, this.all_sessions.size);
 
         bool too_many_free = (
             this.free_queue.size >= this.max_free_size &&
@@ -230,8 +229,8 @@ internal class Geary.Imap.ClientService : Geary.ClientService {
                 try {
                     yield session.close_mailbox_async(pool_cancellable);
                 } catch (ImapError imap_error) {
-                    debug("[%s] Error attempting to close released session %s: %s",
-                          this.account.id, session.to_string(), imap_error.message);
+                    debug("Error attempting to close released session %s: %s",
+                          session.to_string(), imap_error.message);
                     free = false;
                 }
 
@@ -244,8 +243,7 @@ internal class Geary.Imap.ClientService : Geary.ClientService {
             }
 
             if (free) {
-                debug("[%s] Unreserving session %s",
-                      this.account.id, session.to_string());
+                debug("Unreserving session %s", session.to_string());
                 this.free_queue.send(session);
             }
         }
@@ -302,20 +300,19 @@ internal class Geary.Imap.ClientService : Geary.ClientService {
                 this.pool_cancellable
             );
         } catch (ImapError.UNAUTHENTICATED err) {
-            debug("[%s] Auth error adding new session to the pool: %s",
-                  this.account.id, err.message);
+            debug("Auth error adding new session to the pool: %s", err.message);
             notify_authentication_failed();
         } catch (GLib.TlsError.BAD_CERTIFICATE err) {
             // Don't notify of an error here, since the untrusted host
             // handler will be dealing with it already.
-            debug("[%s] TLS validation error adding new session to the pool: %s",
-                  this.account.id, err.message);
+            debug("TLS validation error adding new session to the pool: %s",
+                  err.message);
         } catch (GLib.IOError.CANCELLED err) {
             // Nothing to do here
         } catch (GLib.Error err) {
             Geary.ErrorContext context = new Geary.ErrorContext(err);
-            debug("[%s] Error creating new session for the pool: %s",
-                  this.account.id, context.format_full_error());
+            debug("Error creating new session for the pool: %s",
+                  context.format_full_error());
             notify_connection_failed(context);
         }
 
@@ -331,8 +328,8 @@ internal class Geary.Imap.ClientService : Geary.ClientService {
                 notify_connected();
             } catch (GLib.Error err) {
                 Geary.ErrorContext context = new Geary.ErrorContext(err);
-                debug("[%s] Error adding new session to the pool: %s",
-                      this.account.id, context.format_full_error());
+                debug("Error adding new session to the pool: %s",
+                      context.format_full_error());
                 notify_connection_failed(context);
                 new_session.disconnect_async.begin(null);
                 this.close_pool.begin();
@@ -363,8 +360,7 @@ internal class Geary.Imap.ClientService : Geary.ClientService {
             try {
                 yield remove_session_async(target);
             } catch (Error err) {
-                debug("[%s] Error removing unconnected session: %s",
-                      this.account.id, err.message);
+                debug("Error removing unconnected session: %s", err.message);
             }
             break;
 
@@ -402,7 +398,7 @@ internal class Geary.Imap.ClientService : Geary.ClientService {
     }
 
     private async ClientSession create_new_authorized_session(Cancellable? cancellable) throws Error {
-        debug("[%s] Opening new session", this.account.id);
+        debug("Opening new session");
         Credentials? login = this.configuration.credentials;
         if (login != null && !login.is_complete()) {
             throw new ImapError.UNAUTHENTICATED("Token not loaded");
@@ -420,8 +416,8 @@ internal class Geary.Imap.ClientService : Geary.ClientService {
             try {
                 yield new_session.disconnect_async(null);
             } catch (Error disconnect_err) {
-                debug("[%s] Error disconnecting due to session initiation failure, ignored: %s",
-                    new_session.to_string(), disconnect_err.message);
+                debug("Error disconnecting due to session initiation failure, ignored: %s",
+                      disconnect_err.message);
             }
 
             throw err;
@@ -462,13 +458,12 @@ internal class Geary.Imap.ClientService : Geary.ClientService {
     }
 
     private async void force_disconnect(ClientSession session) {
-        debug("[%s] Dropping session %s", this.account.id, session.to_string());
+        debug("Dropping session %s", session.to_string());
 
         try {
             yield remove_session_async(session);
         } catch (Error err) {
-            debug("[%s] Error removing session: %s",
-                  this.account.id, err.message);
+            debug("Error removing session: %s", err.message);
         }
 
         // Don't wait for this to finish because we don't want to
@@ -499,8 +494,8 @@ internal class Geary.Imap.ClientService : Geary.ClientService {
                 try {
                     this.remove_session_async.end(res);
                 } catch (Error err) {
-                    debug("[%s] Error removing disconnected session: %s",
-                          this.account.id, err.message);
+                    debug("Error removing disconnected session: %s",
+                          err.message);
                 }
             }
         );
diff --git a/src/engine/imap/transport/imap-deserializer.vala 
b/src/engine/imap/transport/imap-deserializer.vala
index 8ca8ec25..6959b09d 100644
--- a/src/engine/imap/transport/imap-deserializer.vala
+++ b/src/engine/imap/transport/imap-deserializer.vala
@@ -252,7 +252,7 @@ public class Geary.Imap.Deserializer : BaseObject {
 
         // wait for outstanding I/O to exit
         yield closed_semaphore.wait_async();
-        debug("[%s] Deserializer closed", to_string());
+        Logging.debug(Logging.Flag.DESERIALIZER, "[%s] Deserializer closed", to_string());
     }
 
     /**
@@ -808,7 +808,7 @@ public class Geary.Imap.Deserializer : BaseObject {
     }
 
     private uint on_eos() {
-        debug("[%s] EOS", to_string());
+        Logging.debug(Logging.Flag.DESERIALIZER, "[%s] EOS", to_string());
 
         // Per RFC 3501 7.1.5, we may get a EOS immediately after a
         // BYE, so flush any message being processed.
@@ -828,7 +828,7 @@ public class Geary.Imap.Deserializer : BaseObject {
         // only Cancellable allowed is internal used to notify when closed; all other errors should
         // be reported
         if (!(err is IOError.CANCELLED)) {
-            debug("[%s] input error: %s", to_string(), err.message);
+            Logging.debug(Logging.Flag.DESERIALIZER, "[%s] input error: %s", to_string(), err.message);
             receive_failure(err);
         }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]