From 456bdeef35ffbfbdad7609e8b8a4ef71372786fd Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 13 Jan 2021 20:00:25 +0100 Subject: [WIP] Add extensible logging API --- src/world.c | 66 +++++-------------------------------------------------------- 1 file changed, 5 insertions(+), 61 deletions(-) (limited to 'src/world.c') diff --git a/src/world.c b/src/world.c index 9f10de49..f5ab2f19 100644 --- a/src/world.c +++ b/src/world.c @@ -3,68 +3,19 @@ #include "world.h" -#include "caret.h" +#include "log.h" #include "node.h" #include "serd/node.h" - +#include "serd/status.h" #include "serd/string_view.h" +#include "serd/world.h" #include -#include #include #include #include -SerdStatus -serd_world_error(const SerdWorld* const world, const SerdError* const e) -{ - if (world->error_func) { - world->error_func(world->error_handle, e); - } else { - fprintf(stderr, "error: "); - if (e->caret) { - fprintf(stderr, - "%s:%u:%u: ", - serd_node_string(e->caret->document), - e->caret->line, - e->caret->col); - } - vfprintf(stderr, e->fmt, *e->args); - fprintf(stderr, "\n"); - } - return e->status; -} - -SerdStatus -serd_world_verrorf(const SerdWorld* const world, - const SerdStatus st, - const char* const fmt, - va_list args) -{ - va_list args_copy; - va_copy(args_copy, args); - - const SerdError e = {st, NULL, fmt, &args_copy}; - serd_world_error(world, &e); - va_end(args_copy); - return st; -} - -SerdStatus -serd_world_errorf(const SerdWorld* const world, - const SerdStatus st, - const char* const fmt, - ...) -{ - va_list args; // NOLINT(cppcoreguidelines-init-variables) - va_start(args, fmt); - const SerdError e = {st, NULL, fmt, &args}; - serd_world_error(world, &e); - va_end(args); - return st; -} - SerdWorld* serd_world_new(void) { @@ -81,6 +32,8 @@ serd_world_new(void) world->limits.writer_max_depth = 128U; world->blank_node = blank_node; + serd_log_init(&world->log); + return world; } @@ -125,12 +78,3 @@ serd_world_get_blank(SerdWorld* const world) #undef BLANK_CHARS } - -void -serd_world_set_error_func(SerdWorld* world, - SerdLogFunc error_func, - void* handle) -{ - world->error_func = error_func; - world->error_handle = handle; -} -- cgit v1.2.1