--- /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 1EB20429E40\r
+ for <notmuch@notmuchmail.org>; Sun, 28 Dec 2014 09:38:41 -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 KZaCZ0DKgA47 for <notmuch@notmuchmail.org>;\r
+ Sun, 28 Dec 2014 09:38:36 -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 B3F8D429E3B\r
+ for <notmuch@notmuchmail.org>; Sun, 28 Dec 2014 09:38:14 -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 1Y5HnC-0002h4-CE; Sun, 28 Dec 2014 13:38:14 -0400\r
+Received: (nullmailer pid 11502 invoked by uid 1000); Sun, 28 Dec 2014\r
+ 17:37:40 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [Patch v3 5/6] lib: replace almost all fprintfs in library with\r
+ _n_d_log\r
+Date: Sun, 28 Dec 2014 18:33:49 +0100\r
+Message-Id: <1419788030-10567-6-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.1.3\r
+In-Reply-To: <1419788030-10567-1-git-send-email-david@tethera.net>\r
+References: <1419788030-10567-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: Sun, 28 Dec 2014 17:38:41 -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
+query debugging output is left as is; it doesn't really fit with the\r
+current primitive logging model. The remaining "bad" fprintf will need\r
+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 | 8 ++++----\r
+ 5 files changed, 33 insertions(+), 30 deletions(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index 9af1a47..19f5f0e 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -493,7 +493,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
+@@ -725,7 +725,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
+@@ -1010,7 +1010,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
+@@ -1142,12 +1142,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
+@@ -1167,20 +1167,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
+@@ -1188,7 +1188,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
+@@ -1217,7 +1217,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
+@@ -1495,7 +1495,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
+@@ -1545,7 +1545,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
+@@ -1579,7 +1579,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
+@@ -1825,7 +1825,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
+@@ -2407,7 +2407,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
+@@ -2499,7 +2499,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
+@@ -2552,7 +2552,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..9ed420c 100644\r
+--- a/lib/query.cc\r
++++ b/lib/query.cc\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
+@@ -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