[geary/mjog/logging-improvements] Geary.Db: Disable SQL query logging by default again



commit 834b6eb4bf7f77e6a2eb8a8bdec968bff14ddbce
Author: Michael Gratton <mike vee net>
Date:   Fri Apr 17 08:49:33 2020 +1000

    Geary.Db: Disable SQL query logging by default again
    
    Even just logging SQL queries is extremely verbose, and pushes a lot
    of logging messages off the end of the buffer. So rework result logging
    flag and code to apply to both again.
    
    Re-merge Application.Client's SQL logging command line flags back into
    one again.

 src/client/application/application-client.vala           | 14 ++++----------
 src/client/components/components-inspector-log-view.vala |  1 -
 src/engine/db/db-connection.vala                         |  8 ++++----
 src/engine/db/db-context.vala                            |  9 +++++++++
 src/engine/db/db-result.vala                             | 10 +---------
 5 files changed, 18 insertions(+), 24 deletions(-)
---
diff --git a/src/client/application/application-client.vala b/src/client/application/application-client.vala
index e2c87b24..523a680f 100644
--- a/src/client/application/application-client.vala
+++ b/src/client/application/application-client.vala
@@ -69,7 +69,6 @@ public class Application.Client : Gtk.Application {
     private const string OPTION_LOG_REPLAY_QUEUE = "log-replay-queue";
     private const string OPTION_LOG_SMTP = "log-smtp";
     private const string OPTION_LOG_SQL = "log-sql";
-    private const string OPTION_LOG_SQL_RESULTS = "log-sql-results";
     private const string OPTION_HIDDEN = "hidden";
     private const string OPTION_NEW_WINDOW = "new-window";
     private const string OPTION_QUIT = "quit";
@@ -124,10 +123,7 @@ public class Application.Client : Gtk.Application {
           N_("Log SMTP messages"), null },
         { OPTION_LOG_SQL, 0, 0, GLib.OptionArg.NONE, null,
           /// Command line option
-          N_("Log database queries"), null },
-        { OPTION_LOG_SQL_RESULTS, 0, 0, GLib.OptionArg.NONE, null,
-          /// Command line option
-          N_("Log database query results (generates lots of messages)"), null },
+          N_("Log database queries (generates lots of messages)"), null },
         { OPTION_QUIT, 'q', 0, GLib.OptionArg.NONE, null,
           /// Command line option
           N_("Perform a graceful quit"), null },
@@ -946,13 +942,11 @@ public class Application.Client : Gtk.Application {
                 Geary.Smtp.ClientService.PROTOCOL_LOGGING_DOMAIN
             );
         }
-        if (!options.contains(OPTION_LOG_SQL) &&
-            !options.contains(OPTION_LOG_SQL_RESULTS)) {
+        if (options.contains(OPTION_LOG_SQL)) {
+            Geary.Db.Context.enable_sql_logging = true;
+        } else {
             Geary.Logging.suppress_domain(Geary.Db.Context.LOGGING_DOMAIN);
         }
-        if (options.contains(OPTION_LOG_SQL_RESULTS)) {
-            Geary.Db.Result.log_results = true;
-        }
 
         if (options.contains(OPTION_HIDDEN)) {
             warning(
diff --git a/src/client/components/components-inspector-log-view.vala 
b/src/client/components/components-inspector-log-view.vala
index c372e829..24653d6f 100644
--- a/src/client/components/components-inspector-log-view.vala
+++ b/src/client/components/components-inspector-log-view.vala
@@ -123,7 +123,6 @@ public class Components.InspectorLogView : Gtk.Grid {
 
         // Prefill well-known engine logging domains
         add_domain(Geary.App.ConversationMonitor.LOGGING_DOMAIN);
-        add_domain(Geary.Db.Context.LOGGING_DOMAIN);
         add_domain(Geary.Imap.ClientService.LOGGING_DOMAIN);
         add_domain(Geary.Imap.ClientService.DESERIALISATION_LOGGING_DOMAIN);
         add_domain(Geary.Imap.ClientService.PROTOCOL_LOGGING_DOMAIN);
diff --git a/src/engine/db/db-connection.vala b/src/engine/db/db-connection.vala
index 2a1424b9..f429b356 100644
--- a/src/engine/db/db-connection.vala
+++ b/src/engine/db/db-connection.vala
@@ -106,12 +106,12 @@ public class Geary.Db.Connection : Geary.Db.Context {
      * See [[http://www.sqlite.org/c3ref/exec.html]]
      */
     public void exec(string sql, Cancellable? cancellable = null) throws Error {
-        check_cancelled("Connection.exec", cancellable);
+        if (Db.Context.enable_sql_logging) {
+            debug("exec:\n\t%s", sql);
+        }
 
+        check_cancelled("Connection.exec", cancellable);
         throw_on_error("Connection.exec", db.exec(sql), sql);
-
-        // Don't use Context.log(), which is designed for logging Results and Statements
-        debug("exec:\n\t%s", sql);
     }
 
     /**
diff --git a/src/engine/db/db-context.vala b/src/engine/db/db-context.vala
index 233afa00..8f3b64d6 100644
--- a/src/engine/db/db-context.vala
+++ b/src/engine/db/db-context.vala
@@ -15,6 +15,15 @@
  */
 public abstract class Geary.Db.Context : BaseObject, Logging.Source {
 
+
+    /**
+     * Determines if SQL queries and results will be logged.
+     *
+     * This will cause extremely verbose logging, so enable with care.
+     */
+    public static bool enable_sql_logging = false;
+
+
     /** The GLib logging domain used by this class. */
     public const string LOGGING_DOMAIN = Logging.DOMAIN + ".Db";
 
diff --git a/src/engine/db/db-result.vala b/src/engine/db/db-result.vala
index 6f255ec6..d1eacf70 100644
--- a/src/engine/db/db-result.vala
+++ b/src/engine/db/db-result.vala
@@ -8,14 +8,6 @@ public class Geary.Db.Result : Geary.Db.Context {
     public bool finished { get; private set; default = false; }
 
 
-    /**
-     * Determines if results will be logged.
-     *
-     * This will cause extremely verbose logging, so enable with care
-     */
-    public static bool log_results = false;
-
-
     public Statement statement { get; private set; }
 
 
@@ -307,7 +299,7 @@ public class Geary.Db.Result : Geary.Db.Context {
 
     [PrintfFormat]
     private void log_result(string fmt, ...) {
-        if (Result.log_results) {
+        if (Db.Context.enable_sql_logging) {
             Statement? stmt = get_statement();
             if (stmt != null) {
                 debug("%s\n\t<%s>",


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