aboutsummaryrefslogtreecommitdiffstats
path: root/src/writer.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-01-13 20:00:25 +0100
committerDavid Robillard <d@drobilla.net>2023-12-02 18:49:08 -0500
commit456bdeef35ffbfbdad7609e8b8a4ef71372786fd (patch)
tree25fabaa4f361f66a2bac860f06722e7f51776cbc /src/writer.c
parentfc2114a10769349d38b3215bc95ded855a2be5b6 (diff)
downloadserd-456bdeef35ffbfbdad7609e8b8a4ef71372786fd.tar.gz
serd-456bdeef35ffbfbdad7609e8b8a4ef71372786fd.tar.bz2
serd-456bdeef35ffbfbdad7609e8b8a4ef71372786fd.zip
[WIP] Add extensible logging API
Diffstat (limited to 'src/writer.c')
-rw-r--r--src/writer.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/writer.c b/src/writer.c
index 940b22a0..94c75625 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -16,6 +16,7 @@
#include "serd/attributes.h"
#include "serd/env.h"
#include "serd/event.h"
+#include "serd/log.h"
#include "serd/node.h"
#include "serd/output_stream.h"
#include "serd/sink.h"
@@ -161,7 +162,7 @@ write_node(SerdWriter* writer,
SerdField field,
SerdStatementFlags flags);
-SERD_NODISCARD static bool
+static bool
supports_abbrev(const SerdWriter* writer)
{
return writer->syntax == SERD_TURTLE || writer->syntax == SERD_TRIG;
@@ -198,7 +199,7 @@ w_err(SerdWriter* writer, SerdStatus st, const char* fmt, ...)
va_list args; // NOLINT(cppcoreguidelines-init-variables)
va_start(args, fmt);
- serd_world_verrorf(writer->world, st, fmt, args);
+ serd_vlogf(writer->world, SERD_LOG_LEVEL_ERROR, fmt, args);
va_end(args);
return st;
@@ -264,9 +265,13 @@ sink(const void* buf, size_t len, SerdWriter* writer)
char message[1024] = {0};
serd_system_strerror(errno, message, sizeof(message));
- w_err(writer, SERD_BAD_WRITE, "write error (%s)\n", message);
+ w_err(writer, SERD_BAD_WRITE, "write error (%s)", message);
} else {
- w_err(writer, SERD_BAD_WRITE, "write error\n");
+ w_err(writer,
+ SERD_BAD_WRITE,
+ "unknown write error, %zu / %zu bytes written",
+ written,
+ len);
}
}
@@ -291,7 +296,7 @@ write_character(SerdWriter* const writer,
const uint32_t c = parse_utf8_char(utf8, size);
switch (*size) {
case 0:
- *st = w_err(writer, SERD_BAD_TEXT, "invalid UTF-8 start: %X\n", utf8[0]);
+ *st = w_err(writer, SERD_BAD_TEXT, "invalid UTF-8 start: %X", utf8[0]);
return 0;
case 1:
snprintf(escape, sizeof(escape), "\\u%04X", utf8[0]);
@@ -864,7 +869,7 @@ write_uri_node(SerdWriter* const writer,
!serd_env_base_uri(writer->env)) {
return w_err(writer,
SERD_BAD_ARG,
- "syntax does not support URI reference <%s>\n",
+ "URI reference <%s> in unsupported syntax",
node_str);
}
@@ -886,7 +891,7 @@ write_curie(SerdWriter* const writer, const SerdNode* const node)
if (!supports_abbrev(writer) || !fast) {
const SerdStringView curie = serd_node_string_view(node);
if ((st = serd_env_expand_in_place(writer->env, curie, &prefix, &suffix))) {
- return w_err(writer, st, "undefined namespace prefix '%s'\n", node_str);
+ return w_err(writer, st, "undefined namespace prefix '%s'", node_str);
}
}
@@ -1307,7 +1312,10 @@ serd_writer_end_anon(SerdWriter* writer, const SerdNode* node)
}
if (!writer->anon_stack_size) {
- return w_err(writer, SERD_BAD_EVENT, "unexpected end of anonymous node\n");
+ return w_err(writer,
+ SERD_BAD_EVENT,
+ "unexpected end of anonymous node '%s'",
+ serd_node_string(node));
}
// Write the end separator ']' and pop the context