Enabling debug logging when running with"zig test"

I’ve been trying for hours and I can’t figure out how to enable debug level logging with std.log when using “zig test” to run tests in a single file, is that even possible?

Tests are super useful for debugging (especially when you use an editor like Zed which does not have a debugger or an AI companion that would like to see your logs) so it’s a bit frustrating that it’s so hard to figure this thing out :slight_smile:

Am I just using it incorrectly and I should use “std.debug” instead?

1 Like

std.testing.log_level = .debug;

11 Likes

Wow, so simple, but so hard to google for, thanks!

Thank you! After wasting too much time trying to figure out why I don’t see logs when running my code in unit test I found this. Surprised me we had to do this, coming from Rust…

1 Like

Me as well. I got really confused when I found out logging wasn’t working as I want because there was a global value assigned.

Not sure If I do not know how to use it, or if it for real is just a global value.