Skip to content

Conversation

@mlugg
Copy link
Member

@mlugg mlugg commented Oct 28, 2025

The main purpose of this branch is the second commit, which changes the default implementation of std.log to colorize the output if the detected TTY config allows it. Here's a comparison of some simple output:

image image

Of course, you can still always override the implementation through root.std_options.logFn.

For this new std.log.defaultLog implementation, we need to know the std.Io.tty.Config for stderr, but we'd ideally like to avoid an extra syscall on every single call to std.log. I have therefore implemented what I think is a good solution to this, which is for std.debug.lockStderrWriter to not only return an Io.Writer, but also an Io.tty.Config, which is detected once and then cached globally. I believe this is reasonable because code outputting to stderr will often want to use the TTY config to colorize that output, and lockStderrWriter is already coordinating access to stderr with global state, so it seems fine to add a little more global state. I think the diff for the change ended up cleaning some things up slightly.

@andrewrk, I'm requesting your review for the std.debug.lockStderrWriter API change explained above. Also let me know if you'd prefer I hold off on the merge to avoid potential std.Io conflicts.

The last commit is just a little fix I snuck in for something I regressed in #25029.

mlugg and others added 5 commits October 30, 2025 09:31
`std.Io.tty.Config.detect` may be an expensive check (e.g. involving
syscalls), and doing it every time we need to print isn't really
necessary; under normal usage, we can compute the value once and cache
it for the whole program's execution. Since anyone outputting to stderr
may reasonably want this information (in fact they are very likely to),
it makes sense to cache it and return it from `lockStderrWriter`. Call
sites who do not need it will experience no significant overhead, and
can just ignore the TTY config with a `const w, _` destructure.
Also remove the example implementation from the file doc comment; it's
better to just link to `defaultLog` as an example, since this avoids
writing the example implementation twice and prevents the example from
bitrotting.
Using '--webui' without '--time-report' when there are Run steps in the
graph was regressed by ziglang#25029.
Copy link
Member

@andrewrk andrewrk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

Another relevant thing to think about is escaping terminal sequences by default when it is known that the output stream is a terminal, with a mechanism to intentionally let them through.

@mlugg mlugg enabled auto-merge October 30, 2025 14:00
@mlugg mlugg merged commit 4174ab9 into ziglang:master Oct 30, 2025
9 checks passed
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.

3 participants