Skip to content

Commit 7526e2b

Browse files
committed
Route log output to frontend
1 parent dfa4f91 commit 7526e2b

File tree

5 files changed

+30
-10
lines changed

5 files changed

+30
-10
lines changed

core/config.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
#include <unistd.h>
44
#include <errno.h>
55
#ifndef _WIN32
6-
#include <limits.h>
6+
#include <limits.h>
7+
#define MM_API __attribute__((visibility ("default")))
8+
#else
9+
#define MM_API __attribute__((dllexport))
710
#endif
811

912
#define BACKEND_NAME "core/cfg"

core/core.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <sys/select.h>
88
#define MM_API __attribute__((visibility ("default")))
99
#else
10+
#include <fcntl.h>
1011
#define MM_API __attribute__((dllexport))
1112
#endif
1213

@@ -223,7 +224,7 @@ int core_iteration(){
223224
}
224225

225226
//run backend processing to collect events
226-
DBGPF("%" PRIsize_t " backend FDs signaled", nfds);
227+
DBGPF("%" PRIsize_t " backend FDs signaled", n);
227228
if(backends_handle(n, signaled_fds)){
228229
return 1;
229230
}

core/plugin.c

+7-5
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
#include <dirent.h>
88
#include "portability.h"
99
#ifdef _WIN32
10-
#define dlclose FreeLibrary
11-
#define dlsym GetProcAddress
12-
#define dlerror() "Failed"
13-
#define dlopen(lib,ig) LoadLibrary(lib)
10+
#define dlclose FreeLibrary
11+
#define dlsym GetProcAddress
12+
#define dlerror() "Failed"
13+
#define dlopen(lib,ig) LoadLibrary(lib)
14+
#define MM_API __attribute__((dllexport))
1415
#else
15-
#include <dlfcn.h>
16+
#include <dlfcn.h>
17+
#define MM_API __attribute__((visibility ("default")))
1618
#endif
1719

1820
#define BACKEND_NAME "core/pl"

midimonster.c

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <string.h>
22
#include <signal.h>
3+
#include <stdarg.h>
34
#ifndef _WIN32
45
#define MM_API __attribute__((visibility("default")))
56
#else
@@ -13,6 +14,16 @@
1314

1415
volatile static sig_atomic_t shutdown_requested = 0;
1516

17+
MM_API int log_printf(int level, char* module, char* fmt, ...){
18+
int rv = 0;
19+
va_list args;
20+
va_start(args, fmt);
21+
fprintf(stderr, "%s%s\t", level ? "debug/" : "", module);
22+
rv = vfprintf(stderr, fmt, args);
23+
va_end(args);
24+
return rv;
25+
}
26+
1627
static void signal_handler(int signum){
1728
shutdown_requested = 1;
1829
}

midimonster.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,19 @@
4040
/* Clamp a value to a range */
4141
#define clamp(val,max,min) (((val) > (max)) ? (max) : (((val) < (min)) ? (min) : (val)))
4242

43+
/* Log function prototype - do not use directly. Use the LOG/LOGPF/DBGPF macros below instead */
44+
MM_API __attribute__((format(printf, 3, 4))) int log_printf(int level, char* module, char* fmt, ...);
45+
4346
/* Debug messages only compile in when DEBUG is set */
4447
#ifdef DEBUG
45-
#define DBGPF(format, ...) fprintf(stderr, "debug/%s\t" format "\n", (BACKEND_NAME), __VA_ARGS__)
48+
#define DBGPF(format, ...) log_printf(1, (BACKEND_NAME), format "\n", __VA_ARGS__)
4649
#else
4750
#define DBGPF(format, ...)
4851
#endif
4952

5053
/* Log messages should be routed through these macros to ensure interoperability with different core implementations */
51-
#define LOGPF(format, ...) fprintf(stderr, "%s\t" format "\n", (BACKEND_NAME), __VA_ARGS__)
52-
#define LOG(message) fprintf(stderr, "%s\t%s\n", (BACKEND_NAME), (message))
54+
#define LOGPF(format, ...) log_printf(0, (BACKEND_NAME), format "\n", __VA_ARGS__)
55+
#define LOG(message) log_printf(0, (BACKEND_NAME), message "\n")
5356

5457
/* Stop compilation if the build system reports an error */
5558
#ifdef BUILD_ERROR

0 commit comments

Comments
 (0)