From 87f165ac89990a89198f256e1794e14d2d07dae3 Mon Sep 17 00:00:00 2001 From: Gediminas Jakutis Date: Thu, 3 Oct 2019 10:22:20 +0300 Subject: diagnostic: allow setting output stream(s). Added a function to allow changing a channel's output stream. This also makes it possible to direct output to a file. Signed-off-by: Gediminas Jakutis --- include/rin/diagnostic.h | 10 ++++++++++ src/diagnostic/diagnostic.c | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/rin/diagnostic.h b/include/rin/diagnostic.h index 64b44ef..f60008d 100644 --- a/include/rin/diagnostic.h +++ b/include/rin/diagnostic.h @@ -21,6 +21,8 @@ #ifndef LIBRIN_DIAGNOSTIC_INCLUDED #define LIBRIN_DIAGNOSTIC_INCLUDED +#include + #define RIN_DIAG_SET 1 #define RIN_DIAG_UNSET 0 #define RIN_DIAG_PREFIX (1 << 0) @@ -30,7 +32,15 @@ RIN_DIAG_TIME | \ RIN_DIAG_THREADNUM) +enum rin_diag_outstream { + rin_diag_err, + rin_diag_warn, + rin_diag_fixme, + rin_diag_info +}; + int rin_diag_flags(int flag, int action); +int rin_diag_set_outstream(enum rin_diag_outstream channel, FILE *stream); void rin_err(const char *format, ...); void rin_fixme(const char *format, ...); diff --git a/src/diagnostic/diagnostic.c b/src/diagnostic/diagnostic.c index 9bb4396..58a0292 100644 --- a/src/diagnostic/diagnostic.c +++ b/src/diagnostic/diagnostic.c @@ -45,6 +45,32 @@ int rin_diag_flags(int flag, int action) return 0; } +int rin_diag_set_outstream(enum rin_diag_outstream channel, FILE *stream) +{ + if (!stream) { + return EINVAL; + } + + switch (channel) { + case rin_diag_err: + state.err = stream; + break; + case rin_diag_warn: + state.warn = stream; + break; + case rin_diag_fixme: + state.fixme = stream; + break; + case rin_diag_info: + state.info = stream; + break; + default: + return EINVAL; + } + + return 0; +} + void rin_err(const char *format, ...) { va_list args; -- cgit v1.2.3