Skip to content

Commit de3e497

Browse files
committed
Add std.debug.print for "printf debugging"
1 parent 8e5393a commit de3e497

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/std/debug.zig

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,24 @@ pub const LineInfo = struct {
5252

5353
var stderr_mutex = std.Mutex.init();
5454

55-
/// Deprecated. Use `std.log` functions for logging.
55+
/// Deprecated. Use `std.log` functions for logging or `std.debug.print` for
56+
/// "printf debugging".
5657
pub fn warn(comptime fmt: []const u8, args: var) void {
5758
const held = stderr_mutex.acquire();
5859
defer held.release();
5960
const stderr = io.getStdErr().writer();
6061
nosuspend stderr.print(fmt, args) catch return;
6162
}
6263

64+
/// Print to stderr, unbuffered, and silently returning on failure. Intended
65+
/// for use in "printf debugging." Use `std.log` functions for proper logging.
66+
pub fn print(comptime fmt: []const u8, args: var) void {
67+
const held = stderr_mutex.acquire();
68+
defer held.release();
69+
const stderr = io.getStdErr().writer();
70+
nosuspend stderr.print(fmt, args) catch return;
71+
}
72+
6373
pub fn getStderrMutex() *std.Mutex {
6474
return &stderr_mutex;
6575
}

0 commit comments

Comments
 (0)