From 485cf6569402107c457c7c44de05ffce0d59e4b1 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Wed, 12 Feb 2020 22:32:14 -0500 Subject: [PATCH] Default to mpw_log_sink_file if no sinks are registered. --- platform-independent/c/core/src/mpw-util.c | 2 ++ platform-independent/c/core/src/mpw-util.h | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/platform-independent/c/core/src/mpw-util.c b/platform-independent/c/core/src/mpw-util.c index e879712e..fa1ebacb 100644 --- a/platform-independent/c/core/src/mpw-util.c +++ b/platform-independent/c/core/src/mpw-util.c @@ -103,6 +103,8 @@ void mpw_log_ssink(LogLevel level, const char *file, int line, const char *funct if (sink) sink( &record ); } + if (!sinks_count) + mpw_log_sink_file( &record ); if (record.level <= LogLevelFatal) abort(); diff --git a/platform-independent/c/core/src/mpw-util.h b/platform-independent/c/core/src/mpw-util.h index c43b4634..fd93a0a8 100644 --- a/platform-independent/c/core/src/mpw-util.h +++ b/platform-independent/c/core/src/mpw-util.h @@ -53,12 +53,14 @@ typedef struct { const char *message; } MPLogEvent; -/** A log sink describes a function that can receive log events when registered. */ +/** A log sink describes a function that can receive log events. */ typedef void (MPLogSink)(const MPLogEvent *event); + +/** To receive events, sinks need to be registered. If no sinks are registered, log events are sent to the mpw_log_sink_file sink. */ bool mpw_log_sink_register(MPLogSink *sink); bool mpw_log_sink_unregister(MPLogSink *sink); -/** mpw_log_sink_file is a sink that writes log messages to the mpw_log_cli_file, which defaults to stderr. */ +/** mpw_log_sink_file is a sink that writes log messages to the mpw_log_sink_file, which defaults to stderr. */ extern MPLogSink mpw_log_sink_file; extern FILE *mpw_log_sink_file_target;