Forward native standard streams to platform diagnostics - #233
Open
bkaradzic-microsoft wants to merge 7 commits into
Open
Forward native standard streams to platform diagnostics#233bkaradzic-microsoft wants to merge 7 commits into
bkaradzic-microsoft wants to merge 7 commits into
Conversation
Add an opt-in Foundation utility that tees process stdout and stderr to platform diagnostics while preserving the original stream destinations. Use it in the Android unit-test host and cover lifecycle and tee behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 88569c10-a7ff-4373-9a58-afa9c68b8c09
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a cross-platform Babylon::StandardStreamLogger in Foundation to forward native stdout/stderr output into platform diagnostic channels (Windows OutputDebugString, Android logcat, Apple unified logging) while preserving the original stream destinations, and wires it into the Android unit-test host plus new unit coverage.
Changes:
- Introduces
Babylon::StandardStreamLoggerAPI + implementation with start/stop lifecycle and per-platform forwarding. - Adds a new lifecycle unit test and builds it into the shared unit-test targets (including Android JNI test library).
- Replaces the Android unit-test host’s prior stdout logger with the shared StandardStreamLogger.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| Core/Foundation/Source/StandardStreamLogger.cpp | Implements platform-specific stream redirection, background draining, and forwarding to platform diagnostics. |
| Core/Foundation/Include/Babylon/StandardStreamLogger.h | Declares the opt-in Start/Stop/IsStarted API contract. |
| Core/Foundation/CMakeLists.txt | Adds the new logger sources to Foundation and links Android’s log library when needed. |
| Tests/UnitTests/Shared/StandardStreamLogger.cpp | Adds a lifecycle unit test plus stdout capture helper to validate start/stop behavior. |
| Tests/UnitTests/CMakeLists.txt | Includes the new shared test source in the unit test build. |
| Tests/UnitTests/Android/app/src/main/cpp/JNI.cpp | Starts/stops the StandardStreamLogger around Android unit test execution. |
| Tests/UnitTests/Android/app/src/main/cpp/CMakeLists.txt | Builds the new shared test into the Android JNI unit-test library. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Use CreatePipe/_open_osfhandle and _sopen_s so the Windows path builds on UWP, and stop writing to stderr in the lifecycle test because iOS CI captures simctl launch stderr as the process exit code. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 88569c10-a7ff-4373-9a58-afa9c68b8c09
Avoid a concurrent exec inheriting the write end and delaying Drain EOF on Stop. Windows already creates non-inheritable pipe ends. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 88569c10-a7ff-4373-9a58-afa9c68b8c09
bkaradzic-microsoft
left a comment
Member
Author
There was a problem hiding this comment.
Re-requesting Balanced Copilot review after CLOEXEC fix and replies.
Keep timed-out drain futures so Start() cannot install a second tee while a detached drain is still alive. Consume pending lines with a start index to avoid quadratic erase, document the 3800-byte platform line cap and IsStarted() contract, and log Android Stop() failures to logcat. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 88569c10-a7ff-4373-9a58-afa9c68b8c09
bkaradzic-microsoft
requested review from
CedricGuillemet,
bghgary and
ryantrem
August 27, 2026 22:51
ryantrem
reviewed
Aug 28, 2026
Match AppRuntime: shared API + one JSRUNTIMEHOST_PLATFORM implementation. Windows (Win32/UWP), Android, Apple, and Unix each get their own source file; Android/Apple share the POSIX tee body via an .inl. Also fix IsStarted() doc comment indentation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 88569c10-a7ff-4373-9a58-afa9c68b8c09
ryantrem
reviewed
Aug 28, 2026
Pull Drain/StartChannel/StopChannel into StandardStreamLogger_Shared.inl and leave each platform TU as thin OS ops (fd/pipe/null, diagnostic sink, and Windows StdHandle hooks). Android/Apple share POSIX fd helpers via StandardStreamLogger_PosixOps.inl. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 88569c10-a7ff-4373-9a58-afa9c68b8c09
ryantrem
reviewed
Aug 28, 2026
Android/Apple already #include PosixOps.inl; the CMake entries are IDE-only. Mark .inl files HEADER_FILE_ONLY and document that so they are not mistaken for separate translation units. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 88569c10-a7ff-4373-9a58-afa9c68b8c09
ryantrem
approved these changes
Aug 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Captures process-level
stdoutandstderrso native and third-party diagnostics reach each platform's normal diagnostic channel without routing through JavaScript.What
Babylon::StandardStreamLoggerinCore/Foundation.OutputDebugString.AndroidExtensions::StdoutLoggerwith the shared implementation.Start()andStop()are idempotent. The host opts in before initializing third-party libraries, andStop()restores the original destinations and drains pending output.Why
The original
JsConsoleLoggerdesign only captured migrated call sites, required a liveNapi::Env, and could not capture libraries writing directly throughprintforfprintf. Redirecting the process streams at the application boundary covers both first-party and third-party native output while preserving existing terminal, file, parent-process, and CI destinations.Tests