// Fetch how many workers we would launch
c->max_workers = sysconf(_SC_NPROCESSORS_ONLN);
+ // Set the default log callback
+ fireperf_set_log_callback(c, NULL, NULL);
+
// Parse the command line
r = parse_argv(c, argc, argv);
if (r)
#define FIREPERF_CTX_H
#include <netinet/in.h>
+#include <stdarg.h>
#include "constants.h"
#include "stats.h"
// Forward declarations
struct fireperf_worker;
+typedef void (*fireperf_log_callback)(void* data, int priority, const char* file,
+ int line, const char* fn, const char* format, va_list args);
+
struct fireperf_ctx {
+ // Logging
+ struct {
+ fireperf_log_callback callback;
+ void* data;
+ } log;
+
// TUI
struct fireperf_tui* tui;
return ctx->loglevel;
}
-static void fireperf_log_console(struct fireperf_ctx* ctx, int priority,
+static void fireperf_log_console(void* data, int priority,
const char* file, int line, const char* fn, const char* format, va_list args) {
+ struct fireperf_ctx* ctx = data;
+
switch (priority) {
// Print error messages to stderr
case LOG_ERR:
}
}
+void fireperf_set_log_callback(struct fireperf_ctx* ctx,
+ fireperf_log_callback callback, void* data) {
+ if (!callback) {
+ callback = fireperf_log_console;
+ data = ctx;
+ }
+
+ ctx->log.callback = callback;
+ ctx->log.data = data;
+}
+
void fireperf_log(struct fireperf_ctx* ctx, int priority,
const char* file, int line, const char* fn, const char* format, ...) {
va_list args;
+ // Return immediately if we don't have a callback registered
+ if (!ctx->log.callback)
+ return;
+
va_start(args, format);
- fireperf_log_console(ctx, priority, file, line, fn, format, args);
+ ctx->log.callback(ctx->log.data, priority, file, line, fn, format, args);
va_end(args);
}
int fireperf_get_log_level(struct fireperf_ctx* ctx);
+void fireperf_set_log_callback(struct fireperf_ctx* ctx,
+ fireperf_log_callback callback, void* data);
+
void fireperf_log(struct fireperf_ctx* ctx,
int priority, const char* file, int line, const char* fn,
const char* format, ...) __attribute__((format(printf, 6, 7)));
struct epoll_event events[EPOLL_MAX_EVENTS];
+ INFO(ctx, "Ready...\n");
+
// Main loop
for (;;) {
ready = epoll_wait(epollfd, events, EPOLL_MAX_EVENTS, -1);