[feat] STAR-13 (BOX-06): console capture for print/log#22
Conversation
EnableConsoleCapture routes a Box's console output into an in-memory, drainable Console instead of stderr: print() becomes a LevelPrint entry, and the log module's calls become leveled entries whose keyword arguments are preserved as structured Fields (never pre-rendered into the message). A single unified buffer keeps print and log entries in script call order; Console.Drain returns and clears it for the per-run drain pattern. Capture reuses the existing print-func and logger wiring (it sets the machine print function and the log module's logger), so it takes precedence over SetPrintFunc/SetLogger. Note: the old "log.fatal kills the host" concern is disproven upstream - starlet's log module maps fatal to Errorw and never calls os.Exit. Tests: print-only, log with raw fields, interleaved order, per-run drain, not-enabled nil, after-exec panic guard, and white-box core With/Sync.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 59 |
| Duplication | 4 |
🟢 Coverage 100.00% diff coverage · +0.08% coverage variation
Metric Results Coverage variation ✅ +0.08% coverage variation (-1.00%) Diff coverage ✅ 100.00% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (46b6c85) 1073 1060 98.79% Head commit (1ffac86) 1147 (+74) 1134 (+74) 98.87% (+0.08%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#22) 74 74 100.00% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #22 +/- ##
==========================================
+ Coverage 98.37% 98.48% +0.11%
==========================================
Files 11 12 +1
Lines 799 859 +60
==========================================
+ Hits 786 846 +60
Misses 7 7
Partials 6 6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
STAR-13 / BOX-06
Add
EnableConsoleCaptureso a Box can collect its script's console output instead of emitting it straight to stderr.API
Starbox.EnableConsoleCapture() *Console— installs the capture and returns the buffer.Starbox.Console() *Console— the buffer, or nil if capture was never enabled.Console.Drain() []ConsoleEntry— returns the buffered entries and clears them (per-run drain);Console.Len()reports the undrained count.ConsoleEntry{Time, Level, Message, Fields}+ConsoleField{Key, Value};LevelPrintis the level forprint().Behavior
print()→ aLevelPrintentry (no fields).log.<level>()(when thelogmodule is loaded) → a leveled entry; keyword args are kept as structuredFieldsverbatim, never rendered into the message (positional args fold into the message exactly as the log module renders them).SetPrintFunc/SetLogger; it panics if called after execution.The log half is captured via a small
zapcore.Corethat records each entry into theConsole, recovering raw field values without a per-type switch.Tests
console_test.go: print-only, log-with-raw-fields, interleaved order, per-run drain, not-enabled-nil.console_internal_test.go: white-box coreWith/Sync. Plus the after-exec panic guard inTestSetAddRunPanic.console.gocoverage 100%;gofmt/go vetclean;go test -race -count=2and the Dockergolang:1.19floor green.