--- /dev/null
+Return-Path: <bremner@tesseract.cs.unb.ca>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 00B0C429E2F\r
+ for <notmuch@notmuchmail.org>; Fri, 26 Dec 2014 09:43:34 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+ autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id GzYdMpBVfNUu for <notmuch@notmuchmail.org>;\r
+ Fri, 26 Dec 2014 09:43:27 -0800 (PST)\r
+Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155])\r
+ (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 0AD6A429E26\r
+ for <notmuch@notmuchmail.org>; Fri, 26 Dec 2014 09:43:26 -0800 (PST)\r
+Received: from remotemail by yantan.tethera.net with local (Exim 4.80)\r
+ (envelope-from <bremner@tesseract.cs.unb.ca>)\r
+ id 1Y4Yv7-000604-DA; Fri, 26 Dec 2014 13:43:25 -0400\r
+Received: (nullmailer pid 21758 invoked by uid 1000); Fri, 26 Dec 2014\r
+ 17:43:08 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 3/4] lib: replace almost all fprintfs in library with n_d_log\r
+Date: Fri, 26 Dec 2014 18:42:40 +0100\r
+Message-Id: <1419615761-21581-4-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.1.3\r
+In-Reply-To: <1419615761-21581-1-git-send-email-david@tethera.net>\r
+References: <1419615761-21581-1-git-send-email-david@tethera.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 26 Dec 2014 17:43:35 -0000\r
+\r
+This is not supposed to change any functionality from an end user\r
+point of view. The remaining fprintf will need an internal API change.\r
+---\r
+ lib/database.cc | 56 ++++++++++++++++++++++++++++----------------------------\r
+ lib/directory.cc | 4 ++--\r
+ lib/index.cc | 11 +++++++----\r
+ lib/message.cc | 6 +++---\r
+ lib/query.cc | 18 +++++++++---------\r
+ 5 files changed, 49 insertions(+), 46 deletions(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index f3c62ee..8143758 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -450,7 +450,7 @@ notmuch_database_find_message (notmuch_database_t *notmuch,\r
+ \r
+ return NOTMUCH_STATUS_SUCCESS;\r
+ } catch (const Xapian::Error &error) {\r
+- fprintf (stderr, "A Xapian exception occurred finding message: %s.\n",\r
++ notmuch_database_log (notmuch, "A Xapian exception occurred finding message: %s.\n",\r
+ error.get_msg().c_str());\r
+ notmuch->exception_reported = TRUE;\r
+ *message_ret = NULL;\r
+@@ -609,21 +609,21 @@ notmuch_database_create (const char *path, notmuch_database_t **database)\r
+ int err;\r
+ \r
+ if (path == NULL) {\r
+- fprintf (stderr, "Error: Cannot create a database for a NULL path.\n");\r
++ notmuch_database_log (notmuch, "Error: Cannot create a database for a NULL path.\n");\r
+ status = NOTMUCH_STATUS_NULL_POINTER;\r
+ goto DONE;\r
+ }\r
+ \r
+ err = stat (path, &st);\r
+ if (err) {\r
+- fprintf (stderr, "Error: Cannot create database at %s: %s.\n",\r
++ notmuch_database_log (notmuch, "Error: Cannot create database at %s: %s.\n",\r
+ path, strerror (errno));\r
+ status = NOTMUCH_STATUS_FILE_ERROR;\r
+ goto DONE;\r
+ }\r
+ \r
+ if (! S_ISDIR (st.st_mode)) {\r
+- fprintf (stderr, "Error: Cannot create database at %s: Not a directory.\n",\r
++ notmuch_database_log (notmuch, "Error: Cannot create database at %s: Not a directory.\n",\r
+ path);\r
+ status = NOTMUCH_STATUS_FILE_ERROR;\r
+ goto DONE;\r
+@@ -634,7 +634,7 @@ notmuch_database_create (const char *path, notmuch_database_t **database)\r
+ err = mkdir (notmuch_path, 0755);\r
+ \r
+ if (err) {\r
+- fprintf (stderr, "Error: Cannot create directory %s: %s.\n",\r
++ notmuch_database_log (notmuch, "Error: Cannot create directory %s: %s.\n",\r
+ notmuch_path, strerror (errno));\r
+ status = NOTMUCH_STATUS_FILE_ERROR;\r
+ goto DONE;\r
+@@ -671,7 +671,7 @@ notmuch_status_t\r
+ _notmuch_database_ensure_writable (notmuch_database_t *notmuch)\r
+ {\r
+ if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY) {\r
+- fprintf (stderr, "Cannot write to a read-only database.\n");\r
++ notmuch_database_log (notmuch, "Cannot write to a read-only database.\n");\r
+ return NOTMUCH_STATUS_READ_ONLY_DATABASE;\r
+ }\r
+ \r
+@@ -770,27 +770,27 @@ notmuch_database_open (const char *path,\r
+ static int initialized = 0;\r
+ \r
+ if (path == NULL) {\r
+- fprintf (stderr, "Error: Cannot open a database for a NULL path.\n");\r
++ notmuch_database_log (notmuch, "Error: Cannot open a database for a NULL path.\n");\r
+ status = NOTMUCH_STATUS_NULL_POINTER;\r
+ goto DONE;\r
+ }\r
+ \r
+ if (! (notmuch_path = talloc_asprintf (local, "%s/%s", path, ".notmuch"))) {\r
+- fprintf (stderr, "Out of memory\n");\r
++ notmuch_database_log (notmuch, "Out of memory\n");\r
+ status = NOTMUCH_STATUS_OUT_OF_MEMORY;\r
+ goto DONE;\r
+ }\r
+ \r
+ err = stat (notmuch_path, &st);\r
+ if (err) {\r
+- fprintf (stderr, "Error opening database at %s: %s\n",\r
++ notmuch_database_log (notmuch, "Error opening database at %s: %s\n",\r
+ notmuch_path, strerror (errno));\r
+ status = NOTMUCH_STATUS_FILE_ERROR;\r
+ goto DONE;\r
+ }\r
+ \r
+ if (! (xapian_path = talloc_asprintf (local, "%s/%s", notmuch_path, "xapian"))) {\r
+- fprintf (stderr, "Out of memory\n");\r
++ notmuch_database_log (notmuch, "Out of memory\n");\r
+ status = NOTMUCH_STATUS_OUT_OF_MEMORY;\r
+ goto DONE;\r
+ }\r
+@@ -830,7 +830,7 @@ notmuch_database_open (const char *path,\r
+ * means a dramatically incompatible change. */\r
+ version = notmuch_database_get_version (notmuch);\r
+ if (version > NOTMUCH_DATABASE_VERSION) {\r
+- fprintf (stderr,\r
++ notmuch_database_log (notmuch,\r
+ "Error: Notmuch database at %s\n"\r
+ " has a newer database format version (%u) than supported by this\n"\r
+ " version of notmuch (%u).\n",\r
+@@ -849,7 +849,7 @@ notmuch_database_open (const char *path,\r
+ version, mode == NOTMUCH_DATABASE_MODE_READ_WRITE ? 'w' : 'r',\r
+ &incompat_features);\r
+ if (incompat_features) {\r
+- fprintf (stderr,\r
++ notmuch_database_log (notmuch,\r
+ "Error: Notmuch database at %s\n"\r
+ " requires features (%s)\n"\r
+ " not supported by this version of notmuch.\n",\r
+@@ -899,7 +899,7 @@ notmuch_database_open (const char *path,\r
+ notmuch->query_parser->add_prefix (prefix->name, prefix->prefix);\r
+ }\r
+ } catch (const Xapian::Error &error) {\r
+- fprintf (stderr, "A Xapian exception occurred opening database: %s\n",\r
++ notmuch_database_log (notmuch, "A Xapian exception occurred opening database: %s\n",\r
+ error.get_msg().c_str());\r
+ notmuch_database_destroy (notmuch);\r
+ notmuch = NULL;\r
+@@ -961,7 +961,7 @@ notmuch_database_close (notmuch_database_t *notmuch)\r
+ } catch (const Xapian::Error &error) {\r
+ status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
+ if (! notmuch->exception_reported) {\r
+- fprintf (stderr, "Error: A Xapian exception occurred closing database: %s\n",\r
++ notmuch_database_log (notmuch, "Error: A Xapian exception occurred closing database: %s\n",\r
+ error.get_msg().c_str());\r
+ }\r
+ }\r
+@@ -1088,12 +1088,12 @@ notmuch_database_compact (const char *path,\r
+ }\r
+ \r
+ if (stat (backup_path, &statbuf) != -1) {\r
+- fprintf (stderr, "Path already exists: %s\n", backup_path);\r
++ notmuch_database_log (notmuch, "Path already exists: %s\n", backup_path);\r
+ ret = NOTMUCH_STATUS_FILE_ERROR;\r
+ goto DONE;\r
+ }\r
+ if (errno != ENOENT) {\r
+- fprintf (stderr, "Unknown error while stat()ing path: %s\n",\r
++ notmuch_database_log (notmuch, "Unknown error while stat()ing path: %s\n",\r
+ strerror (errno));\r
+ ret = NOTMUCH_STATUS_FILE_ERROR;\r
+ goto DONE;\r
+@@ -1113,20 +1113,20 @@ notmuch_database_compact (const char *path,\r
+ compactor.set_destdir (compact_xapian_path);\r
+ compactor.compact ();\r
+ } catch (const Xapian::Error &error) {\r
+- fprintf (stderr, "Error while compacting: %s\n", error.get_msg().c_str());\r
++ notmuch_database_log (notmuch, "Error while compacting: %s\n", error.get_msg().c_str());\r
+ ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
+ goto DONE;\r
+ }\r
+ \r
+ if (rename (xapian_path, backup_path)) {\r
+- fprintf (stderr, "Error moving %s to %s: %s\n",\r
++ notmuch_database_log (notmuch, "Error moving %s to %s: %s\n",\r
+ xapian_path, backup_path, strerror (errno));\r
+ ret = NOTMUCH_STATUS_FILE_ERROR;\r
+ goto DONE;\r
+ }\r
+ \r
+ if (rename (compact_xapian_path, xapian_path)) {\r
+- fprintf (stderr, "Error moving %s to %s: %s\n",\r
++ notmuch_database_log (notmuch, "Error moving %s to %s: %s\n",\r
+ compact_xapian_path, xapian_path, strerror (errno));\r
+ ret = NOTMUCH_STATUS_FILE_ERROR;\r
+ goto DONE;\r
+@@ -1134,7 +1134,7 @@ notmuch_database_compact (const char *path,\r
+ \r
+ if (! keep_backup) {\r
+ if (rmtree (backup_path)) {\r
+- fprintf (stderr, "Error removing old database %s: %s\n",\r
++ notmuch_database_log (notmuch, "Error removing old database %s: %s\n",\r
+ backup_path, strerror (errno));\r
+ ret = NOTMUCH_STATUS_FILE_ERROR;\r
+ goto DONE;\r
+@@ -1163,7 +1163,7 @@ notmuch_database_compact (unused (const char *path),\r
+ unused (notmuch_compact_status_cb_t status_cb),\r
+ unused (void *closure))\r
+ {\r
+- fprintf (stderr, "notmuch was compiled against a xapian version lacking compaction support.\n");\r
++ notmuch_database_log (notmuch, "notmuch was compiled against a xapian version lacking compaction support.\n");\r
+ return NOTMUCH_STATUS_UNSUPPORTED_OPERATION;\r
+ }\r
+ #endif\r
+@@ -1441,7 +1441,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
+ }\r
+ \r
+ if (private_status) {\r
+- fprintf (stderr,\r
++ notmuch_database_log (notmuch,\r
+ "Upgrade failed while creating ghost messages.\n");\r
+ status = COERCE_STATUS (private_status, "Unexpected status from _notmuch_message_initialize_ghost");\r
+ goto DONE;\r
+@@ -1491,7 +1491,7 @@ notmuch_database_begin_atomic (notmuch_database_t *notmuch)\r
+ try {\r
+ (static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->begin_transaction (false);\r
+ } catch (const Xapian::Error &error) {\r
+- fprintf (stderr, "A Xapian exception occurred beginning transaction: %s.\n",\r
++ notmuch_database_log (notmuch, "A Xapian exception occurred beginning transaction: %s.\n",\r
+ error.get_msg().c_str());\r
+ notmuch->exception_reported = TRUE;\r
+ return NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
+@@ -1525,7 +1525,7 @@ notmuch_database_end_atomic (notmuch_database_t *notmuch)\r
+ if (thresh && atoi (thresh) == 1)\r
+ db->flush ();\r
+ } catch (const Xapian::Error &error) {\r
+- fprintf (stderr, "A Xapian exception occurred committing transaction: %s.\n",\r
++ notmuch_database_log (notmuch, "A Xapian exception occurred committing transaction: %s.\n",\r
+ error.get_msg().c_str());\r
+ notmuch->exception_reported = TRUE;\r
+ return NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
+@@ -1771,7 +1771,7 @@ notmuch_database_get_directory (notmuch_database_t *notmuch,\r
+ *directory = _notmuch_directory_create (notmuch, path,\r
+ NOTMUCH_FIND_LOOKUP, &status);\r
+ } catch (const Xapian::Error &error) {\r
+- fprintf (stderr, "A Xapian exception occurred getting directory: %s.\n",\r
++ notmuch_database_log (notmuch, "A Xapian exception occurred getting directory: %s.\n",\r
+ error.get_msg().c_str());\r
+ notmuch->exception_reported = TRUE;\r
+ status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
+@@ -2353,7 +2353,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch,\r
+ \r
+ _notmuch_message_sync (message);\r
+ } catch (const Xapian::Error &error) {\r
+- fprintf (stderr, "A Xapian exception occurred adding message: %s.\n",\r
++ notmuch_database_log (notmuch, "A Xapian exception occurred adding message: %s.\n",\r
+ error.get_msg().c_str());\r
+ notmuch->exception_reported = TRUE;\r
+ ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
+@@ -2445,7 +2445,7 @@ notmuch_database_find_message_by_filename (notmuch_database_t *notmuch,\r
+ status = NOTMUCH_STATUS_OUT_OF_MEMORY;\r
+ }\r
+ } catch (const Xapian::Error &error) {\r
+- fprintf (stderr, "Error: A Xapian exception occurred finding message by filename: %s\n",\r
++ notmuch_database_log (notmuch, "Error: A Xapian exception occurred finding message by filename: %s\n",\r
+ error.get_msg().c_str());\r
+ notmuch->exception_reported = TRUE;\r
+ status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
+@@ -2498,7 +2498,7 @@ notmuch_database_get_all_tags (notmuch_database_t *db)\r
+ _notmuch_string_list_sort (tags);\r
+ return _notmuch_tags_create (db, tags);\r
+ } catch (const Xapian::Error &error) {\r
+- fprintf (stderr, "A Xapian exception occurred getting tags: %s.\n",\r
++ notmuch_database_log (db, "A Xapian exception occurred getting tags: %s.\n",\r
+ error.get_msg().c_str());\r
+ db->exception_reported = TRUE;\r
+ return NULL;\r
+diff --git a/lib/directory.cc b/lib/directory.cc\r
+index 8daaec8..955ffac 100644\r
+--- a/lib/directory.cc\r
++++ b/lib/directory.cc\r
+@@ -186,7 +186,7 @@ _notmuch_directory_create (notmuch_database_t *notmuch,\r
+ directory->mtime = Xapian::sortable_unserialise (\r
+ directory->doc.get_value (NOTMUCH_VALUE_TIMESTAMP));\r
+ } catch (const Xapian::Error &error) {\r
+- fprintf (stderr,\r
++ notmuch_database_log (notmuch,\r
+ "A Xapian exception occurred creating a directory: %s.\n",\r
+ error.get_msg().c_str());\r
+ notmuch->exception_reported = TRUE;\r
+@@ -228,7 +228,7 @@ notmuch_directory_set_mtime (notmuch_directory_t *directory,\r
+ \r
+ db->replace_document (directory->document_id, directory->doc);\r
+ } catch (const Xapian::Error &error) {\r
+- fprintf (stderr,\r
++ notmuch_database_log (notmuch,\r
+ "A Xapian exception occurred setting directory mtime: %s.\n",\r
+ error.get_msg().c_str());\r
+ notmuch->exception_reported = TRUE;\r
+diff --git a/lib/index.cc b/lib/index.cc\r
+index 1a2e63d..8fce9b8 100644\r
+--- a/lib/index.cc\r
++++ b/lib/index.cc\r
+@@ -314,7 +314,8 @@ _index_mime_part (notmuch_message_t *message,\r
+ const char *charset;\r
+ \r
+ if (! part) {\r
+- fprintf (stderr, "Warning: Not indexing empty mime part.\n");\r
++ notmuch_database_log (_notmuch_message_database (message),\r
++ "Warning: Not indexing empty mime part.\n");\r
+ return;\r
+ }\r
+ \r
+@@ -334,7 +335,8 @@ _index_mime_part (notmuch_message_t *message,\r
+ if (i == 1)\r
+ continue;\r
+ if (i > 1)\r
+- fprintf (stderr, "Warning: Unexpected extra parts of multipart/signed. Indexing anyway.\n");\r
++ notmuch_database_log (_notmuch_message_database (message),\r
++ "Warning: Unexpected extra parts of multipart/signed. Indexing anyway.\n");\r
+ }\r
+ if (GMIME_IS_MULTIPART_ENCRYPTED (multipart)) {\r
+ /* Don't index encrypted parts. */\r
+@@ -357,8 +359,9 @@ _index_mime_part (notmuch_message_t *message,\r
+ }\r
+ \r
+ if (! (GMIME_IS_PART (part))) {\r
+- fprintf (stderr, "Warning: Not indexing unknown mime part: %s.\n",\r
+- g_type_name (G_OBJECT_TYPE (part)));\r
++ notmuch_database_log (_notmuch_message_database (message),\r
++ "Warning: Not indexing unknown mime part: %s.\n",\r
++ g_type_name (G_OBJECT_TYPE (part)));\r
+ return;\r
+ }\r
+ \r
+diff --git a/lib/message.cc b/lib/message.cc\r
+index 43cc078..60601ef 100644\r
+--- a/lib/message.cc\r
++++ b/lib/message.cc\r
+@@ -252,7 +252,7 @@ _notmuch_message_create_for_message_id (notmuch_database_t *notmuch,\r
+ \r
+ doc_id = _notmuch_database_generate_doc_id (notmuch);\r
+ } catch (const Xapian::Error &error) {\r
+- fprintf (stderr, "A Xapian exception occurred creating message: %s\n",\r
++ notmuch_database_log(_notmuch_message_database (message), "A Xapian exception occurred creating message: %s\n",\r
+ error.get_msg().c_str());\r
+ notmuch->exception_reported = TRUE;\r
+ *status_ret = NOTMUCH_PRIVATE_STATUS_XAPIAN_EXCEPTION;\r
+@@ -467,7 +467,7 @@ notmuch_message_get_header (notmuch_message_t *message, const char *header)\r
+ return talloc_strdup (message, value.c_str ());\r
+ \r
+ } catch (Xapian::Error &error) {\r
+- fprintf (stderr, "A Xapian exception occurred when reading header: %s\n",\r
++ notmuch_database_log(_notmuch_message_database (message), "A Xapian exception occurred when reading header: %s\n",\r
+ error.get_msg().c_str());\r
+ message->notmuch->exception_reported = TRUE;\r
+ return NULL;\r
+@@ -920,7 +920,7 @@ notmuch_message_get_date (notmuch_message_t *message)\r
+ try {\r
+ value = message->doc.get_value (NOTMUCH_VALUE_TIMESTAMP);\r
+ } catch (Xapian::Error &error) {\r
+- fprintf (stderr, "A Xapian exception occurred when reading date: %s\n",\r
++ notmuch_database_log(_notmuch_message_database (message), "A Xapian exception occurred when reading date: %s\n",\r
+ error.get_msg().c_str());\r
+ message->notmuch->exception_reported = TRUE;\r
+ return 0;\r
+diff --git a/lib/query.cc b/lib/query.cc\r
+index 60ff8bd..677b130 100644\r
+--- a/lib/query.cc\r
++++ b/lib/query.cc\r
+@@ -78,7 +78,7 @@ notmuch_query_create (notmuch_database_t *notmuch,\r
+ notmuch_query_t *query;\r
+ \r
+ if (_debug_query ())\r
+- fprintf (stderr, "Query string is:\n%s\n", query_string);\r
++ notmuch_database_log (notmuch, "Query string is:\n%s\n", query_string);\r
+ \r
+ query = talloc (notmuch, notmuch_query_t);\r
+ if (unlikely (query == NULL))\r
+@@ -266,9 +266,9 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
+ }\r
+ \r
+ if (_debug_query ()) {\r
+- fprintf (stderr, "Exclude query is:\n%s\n",\r
++ notmuch_database_log (notmuch, "Exclude query is:\n%s\n",\r
+ exclude_query.get_description ().c_str ());\r
+- fprintf (stderr, "Final query is:\n%s\n",\r
++ notmuch_database_log (notmuch, "Final query is:\n%s\n",\r
+ final_query.get_description ().c_str ());\r
+ }\r
+ \r
+@@ -282,9 +282,9 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
+ return &messages->base;\r
+ \r
+ } catch (const Xapian::Error &error) {\r
+- fprintf (stderr, "A Xapian exception occurred performing query: %s\n",\r
++ notmuch_database_log (notmuch, "A Xapian exception occurred performing query: %s\n",\r
+ error.get_msg().c_str());\r
+- fprintf (stderr, "Query string was: %s\n", query->query_string);\r
++ notmuch_database_log (notmuch, "Query string was: %s\n", query->query_string);\r
+ notmuch->exception_reported = TRUE;\r
+ talloc_free (messages);\r
+ return NULL;\r
+@@ -549,9 +549,9 @@ notmuch_query_count_messages (notmuch_query_t *query)\r
+ enquire.set_docid_order(Xapian::Enquire::ASCENDING);\r
+ \r
+ if (_debug_query ()) {\r
+- fprintf (stderr, "Exclude query is:\n%s\n",\r
++ notmuch_database_log (notmuch, "Exclude query is:\n%s\n",\r
+ exclude_query.get_description ().c_str ());\r
+- fprintf (stderr, "Final query is:\n%s\n",\r
++ notmuch_database_log (notmuch, "Final query is:\n%s\n",\r
+ final_query.get_description ().c_str ());\r
+ }\r
+ \r
+@@ -562,9 +562,9 @@ notmuch_query_count_messages (notmuch_query_t *query)\r
+ count = mset.get_matches_estimated();\r
+ \r
+ } catch (const Xapian::Error &error) {\r
+- fprintf (stderr, "A Xapian exception occurred: %s\n",\r
++ notmuch_database_log (notmuch, "A Xapian exception occurred: %s\n",\r
+ error.get_msg().c_str());\r
+- fprintf (stderr, "Query string was: %s\n", query->query_string);\r
++ notmuch_database_log (notmuch, "Query string was: %s\n", query->query_string);\r
+ }\r
+ \r
+ return count;\r
+-- \r
+2.1.3\r
+\r