From 69e469858c83fc34d41759aa40db4f01c046577f Mon Sep 17 00:00:00 2001 From: icex2 Date: Sun, 28 Jan 2024 21:49:08 +0100 Subject: [PATCH] feat(util): Add log function for logging in exception handlers We want this to always be visible, so the log level must be the highest possible. Unfortunately, that's quite the hack around the existing API and how fatal behaves. The log API stopped scaling already a while ago and needs considerable refactoring to consider the various use-cases that emerged since it was first created on alpha versions of bemanitools. --- src/main/util/log.c | 9 +++++++++ src/main/util/log.h | 1 + 2 files changed, 10 insertions(+) diff --git a/src/main/util/log.c b/src/main/util/log.c index 7da1d63..bd64329 100644 --- a/src/main/util/log.c +++ b/src/main/util/log.c @@ -64,6 +64,15 @@ static void log_builtin_format( } } +void log_exception_handler(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + log_builtin_format(LOG_LEVEL_FATAL, LOG_MODULE, fmt, ap); + va_end(ap); +} + void log_assert_body(const char *file, int line, const char *function) { log_impl_fatal("assert", "%s:%d: function `%s'", file, line, function); diff --git a/src/main/util/log.h b/src/main/util/log.h index 47603fa..e8a0bd0 100644 --- a/src/main/util/log.h +++ b/src/main/util/log.h @@ -66,6 +66,7 @@ enum log_level { LOG_LEVEL_MISC = 3, }; +void log_exception_handler(const char *fmt, ...); void log_assert_body(const char *file, int line, const char *function); void log_to_external( log_formatter_t misc,