feat: Add support for logging to Android logcat

This commit is contained in:
Marcel Alexandru Nitan 2024-08-23 14:49:46 +03:00
parent db3d8485d2
commit 26d7d45e0c

View file

@ -12,7 +12,9 @@ terms of the MIT license. A copy of the license can be found in the file
#include <stdio.h> // stdin/stdout
#include <stdlib.h> // abort
#if defined(__ANDROID__)
#include <android/log.h> // Output to android logcat
#endif
static long mi_max_error_count = 16; // stop outputting errors after this (use < 0 for no limit)
static long mi_max_warning_count = 16; // stop outputting warnings after this (use < 0 for no limit)
@ -395,6 +397,9 @@ void _mi_verbose_message(const char* fmt, ...) {
va_list args;
va_start(args,fmt);
mi_vfprintf(NULL, NULL, "mimalloc: ", fmt, args);
#if defined(__ANDROID__)
__android_log_vprint(ANDROID_LOG_VERBOSE, "mimalloc", fmt, args);
#endif
va_end(args);
}
@ -404,6 +409,9 @@ static void mi_show_error_message(const char* fmt, va_list args) {
if (mi_max_error_count >= 0 && (long)mi_atomic_increment_acq_rel(&error_count) > mi_max_error_count) return;
}
mi_vfprintf_thread(NULL, NULL, "mimalloc: error: ", fmt, args);
#if defined(__ANDROID__)
__android_log_vprint(ANDROID_LOG_ERROR, "mimalloc", fmt, args);
#endif
}
void _mi_warning_message(const char* fmt, ...) {
@ -414,6 +422,9 @@ void _mi_warning_message(const char* fmt, ...) {
va_list args;
va_start(args,fmt);
mi_vfprintf_thread(NULL, NULL, "mimalloc: warning: ", fmt, args);
#if defined(__ANDROID__)
__android_log_vprint(ANDROID_LOG_WARN, "mimalloc", fmt, args);
#endif
va_end(args);
}