Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for logging to Android logcat #928

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}

Expand All @@ -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, ...) {
Expand All @@ -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);
}

Expand Down