--- /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 29A06429E39\r
+ for <notmuch@notmuchmail.org>; Sat, 27 Dec 2014 14:06:09 -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 8oInZSVO7RtA for <notmuch@notmuchmail.org>;\r
+ Sat, 27 Dec 2014 14:06:03 -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 54F35431FBC\r
+ for <notmuch@notmuchmail.org>; Sat, 27 Dec 2014 14:05:59 -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 1Y4zUl-0000Dk-1V; Sat, 27 Dec 2014 18:05:59 -0400\r
+Received: (nullmailer pid 1481 invoked by uid 1000); Sat, 27 Dec 2014\r
+ 22:05:48 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 5/6] lib: replace almost all fprintfs in library with\r
+ _n_d_log\r
+Date: Sat, 27 Dec 2014 23:05:36 +0100\r
+Message-Id: <1419717937-1108-6-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.1.3\r
+In-Reply-To: <1419717937-1108-1-git-send-email-david@tethera.net>\r
+References: <1419717937-1108-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: Sat, 27 Dec 2014 22:06:09 -0000\r
+\r
+This is not supposed to change any functionality from an end user\r
+point of view. Note that it will eliminate some output to stderr. The\r
+remaining fprintf will need an internal API change.\r
+---\r
+ lib/database.cc | 34 +++++++++++++++++-----------------\r
+ lib/directory.cc | 4 ++--\r
+ lib/index.cc | 11 +++++++----\r
+ lib/message.cc | 6 +++---\r
+ lib/query.cc | 18 +++++++++---------\r
+ 5 files changed, 38 insertions(+), 35 deletions(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index ee1c982..6906750 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -494,7 +494,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
+@@ -726,7 +726,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
+@@ -1011,7 +1011,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
+@@ -1138,12 +1138,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
+@@ -1163,20 +1163,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
+@@ -1184,7 +1184,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
+@@ -1213,7 +1213,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
+@@ -1491,7 +1491,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
+@@ -1541,7 +1541,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
+@@ -1575,7 +1575,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
+@@ -1821,7 +1821,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
+@@ -2403,7 +2403,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
+@@ -2495,7 +2495,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
+@@ -2548,7 +2548,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..b836ea2 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..9493549 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..541eabc 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..2e20ab2 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