aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2019-01-12 11:50:34 +0100
committerDavid Robillard <d@drobilla.net>2019-04-13 19:15:32 +0200
commit18a4fbdf46e681e66238ebd3f895c3dc850e691e (patch)
tree6c9d4b76cf1794ca8b2862d05094ace4d872cfde
parent1ba62144ef3bc75610971af121a3b5a6dc868f42 (diff)
downloadserd-18a4fbdf46e681e66238ebd3f895c3dc850e691e.tar.gz
serd-18a4fbdf46e681e66238ebd3f895c3dc850e691e.tar.bz2
serd-18a4fbdf46e681e66238ebd3f895c3dc850e691e.zip
Expose and annotate logging functions
-rw-r--r--NEWS1
-rw-r--r--serd/serd.h22
-rw-r--r--src/world.c16
-rw-r--r--src/world.h3
4 files changed, 40 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index d9276887..05d7fe8a 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,7 @@ serd (1.0.0) unstable;
* Use a fixed-size reader stack
* Simplify writer style options
* Simplify streaming API and improve pretty printing
+ * Add logging functions to public API
-- David Robillard <d@drobilla.net> Sat, 19 Jan 2019 13:31:12 +0100
diff --git a/serd/serd.h b/serd/serd.h
index 9b3e35f6..ec5d9228 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -42,6 +42,12 @@
# define SERD_API
#endif
+#if defined(__GNUC__)
+# define SERD_LOG_FUNC(fmt, arg1) __attribute__((format(printf, fmt, arg1)))
+#else
+# define SERD_LOG_FUNC(fmt, arg1)
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -823,6 +829,22 @@ serd_world_set_message_sink(SerdWorld* world,
SerdMessageSink msg_sink,
void* handle);
+/// Write a message to the log
+SERD_API
+SerdStatus
+serd_world_log(const SerdWorld* world, const SerdMessage* msg);
+
+/// Write a message to the log
+SERD_API
+SERD_LOG_FUNC(5, 6)
+SerdStatus
+serd_world_logf(const SerdWorld* world,
+ SerdStatus st,
+ SerdLogLevel level,
+ const SerdCursor* cursor,
+ const char* fmt,
+ ...);
+
/**
@}
@name Environment
diff --git a/src/world.c b/src/world.c
index 483c46a6..7b0343cc 100644
--- a/src/world.c
+++ b/src/world.c
@@ -70,6 +70,22 @@ serd_world_log(const SerdWorld* world, const SerdMessage* msg)
}
SerdStatus
+serd_world_logf(const SerdWorld* world,
+ SerdStatus st,
+ SerdLogLevel level,
+ const SerdCursor* cursor,
+ const char* fmt,
+ ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ const SerdMessage msg = {st, level, cursor, fmt, &args};
+ serd_world_log(world, &msg);
+ va_end(args);
+ return st;
+}
+
+SerdStatus
serd_world_errorf(const SerdWorld* world, SerdStatus st, const char* fmt, ...)
{
va_list args;
diff --git a/src/world.h b/src/world.h
index f4e7ee3e..9d6dd4d2 100644
--- a/src/world.h
+++ b/src/world.h
@@ -39,8 +39,7 @@ struct SerdWorldImpl {
FILE* serd_world_fopen(SerdWorld* world, const char* path, const char* mode);
-SerdStatus serd_world_log(const SerdWorld* world, const SerdMessage* msg);
-
+SERD_LOG_FUNC(3, 4)
SerdStatus
serd_world_errorf(const SerdWorld* world, SerdStatus st, const char* fmt, ...);