|
8 | 8 | #include "llama.h"
|
9 | 9 | #include "llama-impl.h"
|
10 | 10 | #include "sampling.h"
|
| 11 | +#if defined(__ANDROID__) |
| 12 | +#include <android/log.h> |
| 13 | +#endif |
11 | 14 |
|
12 | 15 | namespace rnllama {
|
13 | 16 |
|
@@ -106,16 +109,32 @@ static void llama_batch_add(llama_batch *batch, llama_token id, llama_pos pos, s
|
106 | 109 | static void log(const char *level, const char *function, int line,
|
107 | 110 | const char *format, ...)
|
108 | 111 | {
|
109 |
| - printf("[%s] %s:%d ", level, function, line); |
110 |
| - |
111 | 112 | va_list args;
|
112 |
| - va_start(args, format); |
113 |
| - vprintf(format, args); |
114 |
| - va_end(args); |
115 |
| - |
116 |
| - printf("\n"); |
| 113 | + #if defined(__ANDROID__) |
| 114 | + char prefix[256]; |
| 115 | + snprintf(prefix, sizeof(prefix), "%s:%d %s", function, line, format); |
| 116 | + |
| 117 | + va_start(args, format); |
| 118 | + android_LogPriority priority; |
| 119 | + if (strcmp(level, "ERROR") == 0) { |
| 120 | + priority = ANDROID_LOG_ERROR; |
| 121 | + } else if (strcmp(level, "WARNING") == 0) { |
| 122 | + priority = ANDROID_LOG_WARN; |
| 123 | + } else if (strcmp(level, "INFO") == 0) { |
| 124 | + priority = ANDROID_LOG_INFO; |
| 125 | + } else { |
| 126 | + priority = ANDROID_LOG_DEBUG; |
| 127 | + } |
| 128 | + __android_log_vprint(priority, "RNLlama", prefix, args); |
| 129 | + va_end(args); |
| 130 | + #else |
| 131 | + printf("[%s] %s:%d ", level, function, line); |
| 132 | + va_start(args, format); |
| 133 | + vprintf(format, args); |
| 134 | + va_end(args); |
| 135 | + printf("\n"); |
| 136 | + #endif |
117 | 137 | }
|
118 |
| - |
119 | 138 | static bool rnllama_verbose = false;
|
120 | 139 |
|
121 | 140 | #if RNLLAMA_VERBOSE != 1
|
@@ -311,6 +330,10 @@ struct llama_rn_context
|
311 | 330 | return false;
|
312 | 331 | }
|
313 | 332 | n_ctx = llama_n_ctx(ctx);
|
| 333 | + |
| 334 | + // We can uncomment for debugging or after this fix: https://github.com/ggerganov/llama.cpp/pull/11101 |
| 335 | + // LOG_INFO("%s\n", common_params_get_system_info(params).c_str()); |
| 336 | + |
314 | 337 | return true;
|
315 | 338 | }
|
316 | 339 |
|
|
0 commit comments