From 7526e2b02716760a6ed05b6f35f7e5a67cebdb87 Mon Sep 17 00:00:00 2001 From: cbdev Date: Thu, 1 Jul 2021 23:07:17 +0200 Subject: Route log output to frontend --- midimonster.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'midimonster.h') diff --git a/midimonster.h b/midimonster.h index 64aa1e5..15ce34a 100644 --- a/midimonster.h +++ b/midimonster.h @@ -40,16 +40,19 @@ /* Clamp a value to a range */ #define clamp(val,max,min) (((val) > (max)) ? (max) : (((val) < (min)) ? (min) : (val))) +/* Log function prototype - do not use directly. Use the LOG/LOGPF/DBGPF macros below instead */ +MM_API __attribute__((format(printf, 3, 4))) int log_printf(int level, char* module, char* fmt, ...); + /* Debug messages only compile in when DEBUG is set */ #ifdef DEBUG - #define DBGPF(format, ...) fprintf(stderr, "debug/%s\t" format "\n", (BACKEND_NAME), __VA_ARGS__) + #define DBGPF(format, ...) log_printf(1, (BACKEND_NAME), format "\n", __VA_ARGS__) #else #define DBGPF(format, ...) #endif /* Log messages should be routed through these macros to ensure interoperability with different core implementations */ -#define LOGPF(format, ...) fprintf(stderr, "%s\t" format "\n", (BACKEND_NAME), __VA_ARGS__) -#define LOG(message) fprintf(stderr, "%s\t%s\n", (BACKEND_NAME), (message)) +#define LOGPF(format, ...) log_printf(0, (BACKEND_NAME), format "\n", __VA_ARGS__) +#define LOG(message) log_printf(0, (BACKEND_NAME), message "\n") /* Stop compilation if the build system reports an error */ #ifdef BUILD_ERROR -- cgit v1.2.3