[geary/mjog/logging-improvements: 4/23] Geary.Imap: Update main classes to use new logging framework



commit 3f661ff89bbad7be4aab2ecea0a141b0aa69df87
Author: Michael Gratton <mike vee net>
Date:   Wed Apr 15 14:56:02 2020 +1000

    Geary.Imap: Update main classes to use new logging framework
    
    Ensure ClientService, ClientSession, and ClientConnection uses a
    logging sub-domain, update Deserialiser to implement Logging.Source.

 src/engine/imap/api/imap-client-service.vala       | 13 +++-
 .../imap/transport/imap-client-connection.vala     | 13 +++-
 src/engine/imap/transport/imap-client-session.vala |  9 ++-
 src/engine/imap/transport/imap-deserializer.vala   | 70 +++++++++++++---------
 4 files changed, 71 insertions(+), 34 deletions(-)
---
diff --git a/src/engine/imap/api/imap-client-service.vala b/src/engine/imap/api/imap-client-service.vala
index 7a8a7f84..d961793e 100644
--- a/src/engine/imap/api/imap-client-service.vala
+++ b/src/engine/imap/api/imap-client-service.vala
@@ -1,6 +1,6 @@
 /*
- * Copyright 2016 Software Freedom Conservancy Inc.
- * Copyright 2017-2019 Michael Gratton <mike vee net>
+ * Copyright © 2016 Software Freedom Conservancy Inc.
+ * Copyright © 2017-2020 Michael Gratton <mike vee net>
  *
  * This software is licensed under the GNU Lesser General Public License
  * (version 2.1 or later). See the COPYING file in this distribution.
@@ -22,10 +22,14 @@
 internal class Geary.Imap.ClientService : Geary.ClientService {
 
 
+    /** The GLib logging domain used by this class. */
+    public const string LOGGING_DOMAIN = Logging.DOMAIN + ".Imap";
+
     private const int DEFAULT_MIN_POOL_SIZE = 1;
     private const int DEFAULT_MAX_FREE_SIZE = 1;
     private const int CHECK_NOOP_THRESHOLD_SEC = 5;
 
+
     /**
      * Set to zero or negative value if keepalives should be disabled when a connection has not
      * selected a mailbox.  (This is not recommended.)
@@ -83,6 +87,11 @@ internal class Geary.Imap.ClientService : Geary.ClientService {
      */
     public bool discard_returned_sessions = false;
 
+    /** {@inheritDoc} */
+    public override string logging_domain {
+        get { return LOGGING_DOMAIN; }
+    }
+
     private Nonblocking.Mutex sessions_mutex = new Nonblocking.Mutex();
     private Gee.Set<ClientSession> all_sessions =
         new Gee.HashSet<ClientSession>();
diff --git a/src/engine/imap/transport/imap-client-connection.vala 
b/src/engine/imap/transport/imap-client-connection.vala
index 8d7e54d9..ac2f2585 100644
--- a/src/engine/imap/transport/imap-client-connection.vala
+++ b/src/engine/imap/transport/imap-client-connection.vala
@@ -1,6 +1,6 @@
 /*
- * Copyright 2016 Software Freedom Conservancy Inc.
- * Copyright 2018-2019 Michael Gratton <mike vee net>
+ * Copyright © 2016 Software Freedom Conservancy Inc.
+ * Copyright © 2018-2020 Michael Gratton <mike vee net>
  *
  * This software is licensed under the GNU Lesser General Public License
  * (version 2.1 or later). See the COPYING file in this distribution.
@@ -8,6 +8,9 @@
 
 public class Geary.Imap.ClientConnection : BaseObject, Logging.Source {
 
+    /** The GLib logging domain used by this class. */
+    public const string LOGGING_DOMAIN = ClientService.LOGGING_DOMAIN + ".Net";
+
     /**
      * Default socket timeout duration.
      *
@@ -58,6 +61,11 @@ public class Geary.Imap.ClientConnection : BaseObject, Logging.Source {
         get; protected set; default = Logging.Flag.NETWORK;
     }
 
+    /** {@inheritDoc} */
+    public override string logging_domain {
+        get { return LOGGING_DOMAIN; }
+    }
+
     /** {@inheritDoc} */
     public Logging.Source? logging_parent { get { return _logging_parent; } }
     private weak Logging.Source? _logging_parent = null;
@@ -328,6 +336,7 @@ public class Geary.Imap.ClientConnection : BaseObject, Logging.Source {
         this.deserializer.end_of_stream.connect(on_eos);
         this.deserializer.parameters_ready.connect(on_parameters_ready);
         this.deserializer.receive_failure.connect(on_receive_failure);
+        this.deserializer.set_logging_parent(this);
         yield this.deserializer.start_async();
 
         // Start this running in the "background", it will stop when
diff --git a/src/engine/imap/transport/imap-client-session.vala 
b/src/engine/imap/transport/imap-client-session.vala
index fabee175..42236ff6 100644
--- a/src/engine/imap/transport/imap-client-session.vala
+++ b/src/engine/imap/transport/imap-client-session.vala
@@ -1,6 +1,6 @@
 /*
- * Copyright 2016 Software Freedom Conservancy Inc.
- * Copyright 2019 Michael Gratton <mike vee net>
+ * Copyright © 2016 Software Freedom Conservancy Inc.
+ * Copyright © 2019-2020 Michael Gratton <mike vee net>
  *
  * This software is licensed under the GNU Lesser General Public License
  * (version 2.1 or later). See the COPYING file in this distribution.
@@ -263,6 +263,11 @@ public class Geary.Imap.ClientSession : BaseObject, Logging.Source {
         get; protected set; default = Logging.Flag.ALL;
     }
 
+    /** {@inheritDoc} */
+    public override string logging_domain {
+        get { return ClientService.LOGGING_DOMAIN; }
+    }
+
     /** {@inheritDoc} */
     public Logging.Source? logging_parent { get { return _logging_parent; } }
     private weak Logging.Source? _logging_parent = null;
diff --git a/src/engine/imap/transport/imap-deserializer.vala 
b/src/engine/imap/transport/imap-deserializer.vala
index 2ad9120b..481314a3 100644
--- a/src/engine/imap/transport/imap-deserializer.vala
+++ b/src/engine/imap/transport/imap-deserializer.vala
@@ -1,6 +1,6 @@
 /*
- * Copyright 2016 Software Freedom Conservancy Inc.
- * Copyright 2019 Michael Gratton <mike vee net>
+ * Copyright © 2016 Software Freedom Conservancy Inc.
+ * Copyright © 2019-2020 Michael Gratton <mike vee net>
  *
  * This software is licensed under the GNU Lesser General Public License
  * (version 2.1 or later). See the COPYING file in this distribution.
@@ -25,7 +25,12 @@
  * is buffered, there's no need to buffer the InputStream passed to Deserializer's constructor.
  */
 
-public class Geary.Imap.Deserializer : BaseObject {
+public class Geary.Imap.Deserializer : BaseObject, Logging.Source {
+
+    /** The GLib logging domain used by this class. */
+    public const string LOGGING_DOMAIN = ClientService.LOGGING_DOMAIN + ".Des";
+
+
     private const size_t MAX_BLOCK_READ_SIZE = 4096;
 
     private enum Mode {
@@ -73,6 +78,20 @@ public class Geary.Imap.Deserializer : BaseObject {
         "Geary.Imap.Deserializer", State.TAG, State.COUNT, Event.COUNT,
         state_to_string, event_to_string);
 
+    /** {@inheritDoc} */
+    public Logging.Flag logging_flags {
+        get; protected set; default = Logging.Flag.DESERIALIZER;
+    }
+
+    /** {@inheritDoc} */
+    public override string logging_domain {
+        get { return LOGGING_DOMAIN; }
+    }
+
+    /** {@inheritDoc} */
+    public Logging.Source? logging_parent { get { return _logging_parent; } }
+    private weak Logging.Source? _logging_parent = null;
+
     private string identifier;
     private DataInputStream input;
     private Geary.State.Machine fsm;
@@ -245,7 +264,7 @@ public class Geary.Imap.Deserializer : BaseObject {
         // wait for outstanding I/O to exit
         yield closed_semaphore.wait_async();
         yield this.input.close_async(GLib.Priority.DEFAULT, null);
-        Logging.debug(Logging.Flag.DESERIALIZER, "[%s] Deserializer closed", to_string());
+        debug("Deserializer closed");
     }
 
     /**
@@ -262,11 +281,14 @@ public class Geary.Imap.Deserializer : BaseObject {
         }
     }
 
-    /**
-     * Returns a string representation of this object for debugging.
-     */
-    public string to_string() {
-        return "des:%s/%s".printf(identifier, fsm.get_state_string(fsm.get_state()));
+    /** {@inheritDoc} */
+    public Logging.State to_logging_state() {
+        return new Logging.State(this, fsm.get_state_string(fsm.get_state()));
+    }
+
+    /** Sets the connection's logging parent. */
+    internal void set_logging_parent(Logging.Source parent) {
+        this._logging_parent = parent;
     }
 
     private void next_deserialize_step() {
@@ -310,14 +332,12 @@ public class Geary.Imap.Deserializer : BaseObject {
                 result, out bytes_read
             );
             if (line == null) {
-                Logging.debug(Logging.Flag.DESERIALIZER, "[%s] line EOS", to_string());
-
+                debug("Line EOS");
                 push_eos();
-
                 return;
             }
 
-            Logging.debug(Logging.Flag.DESERIALIZER, "[%s] line: %s", to_string(), line);
+            debug("Line: %s", line);
             bytes_received(bytes_read);
             push_line(line, bytes_read);
         } catch (Error err) {
@@ -334,14 +354,14 @@ public class Geary.Imap.Deserializer : BaseObject {
             // happens when actually pulling data
             size_t bytes_read = this.input.read_async.end(result);
             if (bytes_read == 0 && literal_length_remaining > 0) {
-                Logging.debug(Logging.Flag.DESERIALIZER, "[%s] block EOS", to_string());
+                debug("Block EOS");
 
                 push_eos();
 
                 return;
             }
 
-            Logging.debug(Logging.Flag.DESERIALIZER, "[%s] block %lub", to_string(), bytes_read);
+            debug("Block %lub", bytes_read);
             bytes_received(bytes_read);
 
             // adjust the current buffer's size to the amount that was actually read in
@@ -486,19 +506,15 @@ public class Geary.Imap.Deserializer : BaseObject {
     private void flush_params() {
         bool okay = true;
         if (this.context_stack.size > 1) {
-            Logging.debug(
-                Logging.Flag.DESERIALIZER,
-                "[%s] Unclosed list in parameters",
-                to_string()
-            );
+            debug("Unclosed list in parameters");
             okay = false;
         }
 
         if (!is_current_string_empty() || this.literal_length_remaining > 0) {
-            Logging.debug(
-                Logging.Flag.DESERIALIZER,
+            debug(
                 "Unfinished parameter: string=%s literal remaining=%lu",
-                (!is_current_string_empty()).to_string(), this.literal_length_remaining
+                (!is_current_string_empty()).to_string(),
+                this.literal_length_remaining
             );
             okay = false;
         }
@@ -677,9 +693,7 @@ public class Geary.Imap.Deserializer : BaseObject {
         // We don't go into the error state on syntax error, merely
         // reset, cross our fingers and hope for the best. Maybe
         // there's a better strategy though?
-        Logging.debug(
-            Logging.Flag.DESERIALIZER, "[%s] Syntax error, dropping", to_string()
-        );
+        debug("Syntax error, dropping");
         deserialize_failure();
         reset_params();
         return State.TAG;
@@ -807,7 +821,7 @@ public class Geary.Imap.Deserializer : BaseObject {
     }
 
     private uint on_eos() {
-        Logging.debug(Logging.Flag.DESERIALIZER, "[%s] EOS", to_string());
+        debug("EOS");
 
         // Per RFC 3501 7.1.5, we may get a EOS immediately after a
         // BYE, so flush any message being processed.
@@ -827,7 +841,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)) {
-            Logging.debug(Logging.Flag.DESERIALIZER, "[%s] input error: %s", to_string(), err.message);
+            debug("Input error: %s", err.message);
             receive_failure(err);
         }
 


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