unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: [Patch v6 5/8] lib: add a log function with output to a string in notmuch_database_t
Date: Fri, 27 Mar 2015 23:11:57 +0100	[thread overview]
Message-ID: <1427494320-1483-6-git-send-email-david@tethera.net> (raw)
In-Reply-To: <1427494320-1483-1-git-send-email-david@tethera.net>

In principle in the future this could do something fancier than
asprintf.
---
 lib/database-private.h |  4 ++++
 lib/database.cc        | 24 ++++++++++++++++++++++++
 lib/notmuch-private.h  |  4 ++++
 lib/notmuch.h          |  7 +++++++
 4 files changed, 39 insertions(+)

diff --git a/lib/database-private.h b/lib/database-private.h
index 6d6fa2c..24243db 100644
--- a/lib/database-private.h
+++ b/lib/database-private.h
@@ -154,6 +154,10 @@ struct _notmuch_database {
     unsigned int last_doc_id;
     uint64_t last_thread_id;
 
+    /* error reporting; this value persists only until the
+     * next library call. May be NULL */
+    char *status_string;
+
     Xapian::QueryParser *query_parser;
     Xapian::TermGenerator *term_gen;
     Xapian::ValueRangeProcessor *value_range_processor;
diff --git a/lib/database.cc b/lib/database.cc
index 5d973b9..c114765 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -348,6 +348,23 @@ notmuch_status_to_string (notmuch_status_t status)
     }
 }
 
+void
+_notmuch_database_log (notmuch_database_t *notmuch,
+		      const char *format,
+		      ...)
+{
+    va_list va_args;
+
+    va_start (va_args, format);
+
+    if (notmuch->status_string)
+	talloc_free (notmuch->status_string);
+
+    notmuch->status_string = talloc_vasprintf (notmuch, format, va_args);
+
+    va_end (va_args);
+}
+
 static void
 find_doc_ids_for_term (notmuch_database_t *notmuch,
 		       const char *term,
@@ -860,6 +877,7 @@ notmuch_database_open_verbose (const char *path,
 
     notmuch = talloc_zero (NULL, notmuch_database_t);
     notmuch->exception_reported = FALSE;
+    notmuch->status_string = NULL;
     notmuch->path = talloc_strdup (notmuch, path);
 
     if (notmuch->path[strlen (notmuch->path) - 1] == '/')
@@ -2545,3 +2563,9 @@ notmuch_database_get_all_tags (notmuch_database_t *db)
 	return NULL;
     }
 }
+
+const char *
+notmuch_database_status_string (notmuch_database_t *notmuch)
+{
+    return notmuch->status_string;
+}
diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
index 8a1f2fa..7cb6fd4 100644
--- a/lib/notmuch-private.h
+++ b/lib/notmuch-private.h
@@ -190,6 +190,10 @@ _notmuch_message_id_compressed (void *ctx, const char *message_id);
 notmuch_status_t
 _notmuch_database_ensure_writable (notmuch_database_t *notmuch);
 
+void
+_notmuch_database_log (notmuch_database_t *notmuch,
+		       const char *format, ...);
+
 const char *
 _notmuch_database_relative_path (notmuch_database_t *notmuch,
 				 const char *path);
diff --git a/lib/notmuch.h b/lib/notmuch.h
index c671d82..20c4e01 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -302,6 +302,13 @@ notmuch_database_open_verbose (const char *path,
 			       char **error_message);
 
 /**
+ * Retrieve last status string for given database.
+ *
+ */
+const char *
+notmuch_database_status_string (notmuch_database_t *notmuch);
+
+/**
  * Commit changes and close the given notmuch database.
  *
  * After notmuch_database_close has been called, calls to other
-- 
2.1.4

  parent reply	other threads:[~2015-03-27 22:13 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-27 22:11 Library logging overhaul, round 6 David Bremner
2015-03-27 22:11 ` [Patch v6 1/8] test: Add two tests for error output from notmuch_database_open David Bremner
2015-03-27 22:11 ` [Patch v6 2/8] test: add support for compiling and running C snippets David Bremner
2015-03-27 22:11 ` [Patch v6 3/8] test: add error reporting tests David Bremner
2015-03-27 22:11 ` [Patch v6 4/8] lib: add "verbose" versions of notmuch_database_{open,create} David Bremner
2015-03-28 10:04   ` [Patch v6 4/8] lib: add "verbose" versions of notmuch_database_{open, create} Tomi Ollila
2015-03-28 23:46     ` [Patch v6 4/8] lib: add "verbose" versions of notmuch_database_{open,create} David Bremner
2015-03-27 22:11 ` David Bremner [this message]
2015-03-27 22:11 ` [Patch v6 6/8] lib: add private function to extract the database for a message David Bremner
2015-03-27 22:11 ` [Patch v6 7/8] lib: replace almost all fprintfs in library with _n_d_log David Bremner
2015-03-27 22:12 ` [Patch v6 8/8] lib: eliminate fprintf from _notmuch_message_file_open David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1427494320-1483-6-git-send-email-david@tethera.net \
    --to=david@tethera.net \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).