Skip to content

[feat] CLI-02/C-4: --log-file routes the script log module to a file#13

Merged
vt128 merged 2 commits into
masterfrom
feat/cli-02-log-file
Jun 21, 2026
Merged

[feat] CLI-02/C-4: --log-file routes the script log module to a file#13
vt128 merged 2 commits into
masterfrom
feat/cli-02-log-file

Conversation

@vt128

@vt128 vt128 commented Jun 21, 2026

Copy link
Copy Markdown
Member

CLI-02 / C-4 — --log-file captures the script's log output

When a script uses the log module, --log-file <path> captures its output to
that file at the interpreter level, so a host can collect a run's logs in
one place.

load("log", "info", "warn")
info("starting up")
warn("careful now")
$ ./starcli --log-file run.log job.star
$ cat run.log
2026-06-21T17:32:07.373+0800    info    starting up
2026-06-21T17:32:07.373+0800    warn    careful now

How

starbox routes the log module through the box logger (module.go uses
slog.NewModule(userLog) when one is set), so BuildBox builds a file-backed
zap logger (console encoder, ISO8601 time, all levels) and SetLoggers it when
--log-file is given.

  • Parent directory auto-created; runs append.
  • The logger is memoized per path so web mode (a BuildBox per request)
    shares one open file instead of leaking a descriptor each request.

Tests route a script's log.info to a temp --log-file (nested dir) and assert
the message + level land in the file. README documents it. Coverage 75.9%
(≥ 65); Docker golang:1.22 green.

Completes the CLI-02 set (STAR-19): check (#9) · args (#11) · stdin (#12) · log-file.

vt128 added 2 commits June 21, 2026 17:34
…(STAR-19)

Add --log-file <path>: when a script uses the starlet log module, its output is
captured to that file at the interpreter level, so a host can collect a run's
logs in one place.

- starbox routes the log module through the box logger (module.go: it uses
  slog.NewModule(userLog) when a logger is set), so BuildBox builds a
  file-backed zap logger (console encoder, ISO8601 time, all levels) and
  SetLogger's it when --log-file is given.
- The parent directory is created if needed; runs append. The logger is
  memoized per path so the web mode (a BuildBox per request) shares one open
  file instead of leaking a descriptor each request.

Tests route a script's log.info to a temp --log-file (nested dir) and assert the
message + level land in the file. README documents it. Coverage 75.9%; Docker
golang:1.22 green.
…them

The fileLogger memo holds the log file open for the process lifetime; on
Windows an open file cannot be deleted, so TestProcess_LogFile's t.TempDir
cleanup failed there. Track the *os.File handles and add closeLogFiles(); the
test registers it via t.Cleanup (after TempDir, so LIFO runs it first) to
release the handle before RemoveAll.
@vt128 vt128 merged commit bd4c44e into master Jun 21, 2026
6 checks passed
@vt128 vt128 deleted the feat/cli-02-log-file branch June 21, 2026 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant