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.
This commit is contained in:
Michael Gratton 2020-04-17 08:49:33 +10:00
parent 53bdf9299d
commit 834b6eb4bf
5 changed files with 18 additions and 24 deletions

View file

@ -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(

View file

@ -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);

View file

@ -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 {
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);
}
/**

View file

@ -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";

View file

@ -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>",