Feat(client): report macOS runtime logs to the controller

macOS already handled COMMAND_QUERY_LOG and opened the sub-connection that
sends TOKEN_REPORT_LOG, but the snapshot was always empty: macOS Mprintf went
to NSLog/fprintf(stderr) and never through Logger, so the ring it dumps stayed
empty and both the 运行日志 dialog and MCP get_client_log got nothing.

macOS now writes Logger like Linux does, with enable=false so no second log
file appears under ~/.config/ghost, and Logger mirrors each line to stderr,
which main.mm already redirects to /tmp/ghost.log in daemon and App bundle
mode. Prefix and timestamp match on both sides, so dialog and file can be
compared line for line.

main.mm logged its own lifecycle through NSLog, which never reaches the ring,
so the lines people open the dialog for were missing; those calls now use
Mprintf. The ObjC helpers (ScreenHandler/H264Encoder/InputHandler/Permissions)
keep NSLog and stay file-only. POSIX reports one snapshot per connection, so
reopening 运行日志 takes a fresh one; Windows keeps pushing every 3s.

Verified with a WSL probe built with -D__APPLE__ (ring, incremental dump,
stderr mirror), a MinGW probe for the _WIN32 branch, and a green Linux client
rebuild. Not built or run on a real Mac.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-14 12:08:52 +01:00
1 parent b743de6747
commit a25e89b220
4 files changed
+102 -38

No files matched your search

+25
View File
@@ -47,6 +47,31 @@ TLS Transport:
If the log says "trust anchor exists but failed to load", the client refuses
to connect (fail-closed) until the anchor is fixed or removed.
Client Log:
The controller's host right-click menu ("运行日志") sends COMMAND_QUERY_LOG;
the client opens a sub-connection and reports its in-memory log ring
(Logger, last 1000 lines) as TOKEN_REPORT_LOG. On macOS Mprintf (as defined
by common/logger.h) writes that ring, and Logger mirrors the same line to
stderr, so one Mprintf line reads identically in the dialog and in
/tmp/ghost.log (same prefix and timestamp); content older than the
1000-entry ring exists only in the file. main.mm logs startup, config,
permissions, TLS, WS, connection and exit through Mprintf, so those lines
are all visible in the dialog. The ObjC helper modules (ScreenHandler /
H264Encoder / InputHandler / Permissions) still use NSLog, and the two
"=== ghost ... started ===" banners are raw write(2) calls; all of those
appear only in /tmp/ghost.log. Mprintf lines also no longer go to Apple's
Unified Logging (NSLog in the helpers still does). The MCP tool
get_client_log reads that same ring.
Verify: open "运行日志" for the Mac host; the dialog should show startup
lines such as "=== macOS Ghost Client ===", "Config loaded from ...",
the permission results, "[TLS] transport on first connect: ...", plus
command and heartbeat entries.
Note: the POSIX client reports a snapshot once per connection (the Windows
client keeps pushing increments every 3s). Closing and reopening "运行日志"
takes a fresh snapshot.
Permissions Required:
1. Screen Recording - System Settings > Privacy & Security > Screen Recording
2. Accessibility - System Settings > Privacy & Security > Accessibility