aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorGravatar Austin Clements <amdragon@MIT.EDU>2012-03-13 22:31:30 -0400
committerGravatar David Bremner <bremner@debian.org>2012-03-18 09:14:22 -0300
commit75a05526334b721d719d6c8a8098ff64573e6c1e (patch)
tree7859c2cb2d5dc5521a453c38cc3fe2e709fb1726 /lib
parentb3e4417897f5b27883513c4714f7e84e377b5f5b (diff)
lib: Expose query debug output via an environment variable
Allow query debugging to be enabled at run-time by setting the NOTMUCH_DEBUG_QUERY environment variable to a non-empty string. Previously, enabling query debugging required recompiling, but parsed queries are often useful for tracking down bugs in situations where recompiling is inconvenient.
Diffstat (limited to 'lib')
-rw-r--r--lib/query.cc24
1 files changed, 15 insertions, 9 deletions
diff --git a/lib/query.cc b/lib/query.cc
index ab18fbc6..1e5e99a5 100644
--- a/lib/query.cc
+++ b/lib/query.cc
@@ -64,15 +64,21 @@ _notmuch_doc_id_set_init (void *ctx,
notmuch_doc_id_set_t *doc_ids,
GArray *arr);
+static notmuch_bool_t
+_debug_query (void)
+{
+ char *env = getenv ("NOTMUCH_DEBUG_QUERY");
+ return (env && strcmp (env, "") != 0);
+}
+
notmuch_query_t *
notmuch_query_create (notmuch_database_t *notmuch,
const char *query_string)
{
notmuch_query_t *query;
-#ifdef DEBUG_QUERY
- fprintf (stderr, "Query string is:\n%s\n", query_string);
-#endif
+ if (_debug_query ())
+ fprintf (stderr, "Query string is:\n%s\n", query_string);
query = talloc (NULL, notmuch_query_t);
if (unlikely (query == NULL))
@@ -255,9 +261,9 @@ notmuch_query_search_messages (notmuch_query_t *query)
break;
}
-#if DEBUG_QUERY
- fprintf (stderr, "Final query is:\n%s\n", final_query.get_description().c_str());
-#endif
+ if (_debug_query ())
+ fprintf (stderr, "Final query is:\n%s\n",
+ final_query.get_description ().c_str ());
enquire.set_query (final_query);
@@ -531,9 +537,9 @@ notmuch_query_count_messages (notmuch_query_t *query)
enquire.set_weighting_scheme(Xapian::BoolWeight());
enquire.set_docid_order(Xapian::Enquire::ASCENDING);
-#if DEBUG_QUERY
- fprintf (stderr, "Final query is:\n%s\n", final_query.get_description().c_str());
-#endif
+ if (_debug_query ())
+ fprintf (stderr, "Final query is:\n%s\n",
+ final_query.get_description ().c_str ());
enquire.set_query (final_query);