Feature: Report client run logs from the Android client
Before this change the Android client's run log went to logcat only: Logger's init tried to create a log directory, enable was true, and the in-memory ring that MCP's get_client_log reads was never fed, so the tool returned an empty log for APK hosts. Logger now has an Android branch that skips the directory and file writer and keeps only the ring, which is always written regardless of enable. Mprintf carries the source file and line as on Windows/Linux, and both android_log (Mprintf) and a new android_log_tag (platform LOGI/LOGE, LOGI_SH/LOGE_SH) print to logcat and append to the ring. A new ClientLogThread opens a sub-connection on COMMAND_QUERY_LOG and lets ClientLogHandler send TOKEN_REPORT_LOG plus the full ring as the first packet. It has to be a sub-connection: the server takes the first packet and calls CancelIO, which would drop the main connection. The server side allows get_client_log on kPlatApk and decodes the payload as UTF-8 like the other POSIX clients. Verified on the emulator against a local debug server: get_client_log returned 21 UTF-8 lines including [file:line] Mprintf output, LOGI lines, and the ClientLogThread handshake. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
51747dc0ea
commit
d365a4f948
5 files changed
+99
-14
No files matched your search
+20
-2
@@ -69,6 +69,14 @@ public:
|
||||
instance.enable = stringToBool(var);
|
||||
instance.log("logger.h", __LINE__, "GetEnvironmentVariable: %s=%s\n", name, var);
|
||||
#endif
|
||||
#elif defined(__ANDROID__)
|
||||
// Android:App 沙箱里没有 native 稳定可写的日志目录(可写的 filesDir 归 Java 侧
|
||||
// 管),故不建目录、不写文件;只保留内存 ring buffer,供 MCP 的 get_client_log
|
||||
// 经 TOKEN_REPORT_LOG 取回(logger.cpp 的 android_log/android_log_tag 往这里灌)。
|
||||
char buf[16] = {};
|
||||
snprintf(buf, sizeof(buf), "%d", (int)getpid());
|
||||
instance.pid = buf;
|
||||
instance.enable = false;
|
||||
#else // Linux
|
||||
char buf[16] = {};
|
||||
snprintf(buf, sizeof(buf), "%d", (int)getpid());
|
||||
@@ -391,8 +399,18 @@ inline const char* getFileName(const char* path)
|
||||
#undef Mprintf
|
||||
#endif
|
||||
void UseAndroidLog(void (*cb)(const char*));
|
||||
void android_log(const char* fmt, ...);
|
||||
#define Mprintf android_log
|
||||
|
||||
// Android 的 Mprintf:输出到 logcat,同时写入 Logger 的内存 ring buffer。
|
||||
// 带源文件/行号(与 Windows/Linux 的 Mprintf 对齐),MCP 的 get_client_log 才能从
|
||||
// ring 里取回可定位的日志。
|
||||
void android_log(const char* file, int line, const char* fmt, ...)
|
||||
__attribute__((format(printf, 3, 4)));
|
||||
#define Mprintf(format, ...) android_log(getFileName(__FILE__), __LINE__, format, ##__VA_ARGS__)
|
||||
|
||||
// 平台侧宏(main.cpp 的 LOGI/LOGE、ScreenHandler.h 的 LOGI_SH/LOGE_SH)用:自定义
|
||||
// logcat 优先级与 tag,同样写入 ring,但不带源文件(这些宏只有 tag 没有行号)。
|
||||
void android_log_tag(int prio, const char* tag, const char* fmt, ...)
|
||||
__attribute__((format(printf, 3, 4)));
|
||||
#else
|
||||
// Linux: 覆盖 commands.h 中的 printf 回退定义,改用 Logger 写文件
|
||||
#ifdef Mprintf
|
||||
|
||||
Reference in new issue
Block a user