Now, obviously a poly transmutation is non trivial, and there is a bunch of edge cases that do not warrant for the script to panic, or to systematically write to stderr which will always appear. But maybe I still want to emit some info level log that I could toggle on/off if I run into issues later on.
My first instinct was : Can’t I just make it so that zig build --verbose reveal the logs of my polytransmutation tool ? But it’s a child process know nothing about the --verbose flag.
And the helper script itself, polytransmutate.zig:
pub fn main(init: std.process.Init) !void {
...
const args = try init.minimal.args.toSlice(arena);
const input_file = args[1];
// Now transform file and output result to stdout
// Ooops, I hit a hedge case...
// But it's probably fine ...
// Mmmh, can I log something that appears only in --verbose maybe
}
@compileLog expects comptime values passed to it, and will be executed at compile time.
If you also run polytransmutate.zig in your build.zig as part of the default build step (which I assume you do, since you said it’s an helper script) and you want to log at runtime during the execution by build.zig you can try with std.log, but I’m not sure if that works.