diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2025-07-10 12:41:26 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2025-07-10 16:52:29 -0700 |
| commit | bd5745ddf2f5a5d42553b30241f0a44550f1672e (patch) | |
| tree | 06632df6dbbbb719830929ea5ff36c33b14fef2b /lib | |
| parent | 5360968e03525be4d312ca61a7ba2dcb7890ec42 (diff) | |
| download | zig-bd5745ddf2f5a5d42553b30241f0a44550f1672e.tar.gz zig-bd5745ddf2f5a5d42553b30241f0a44550f1672e.zip | |
std.log.defaultLog: provide a small buffer
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/std/log.zig | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/lib/std/log.zig b/lib/std/log.zig index 20792dcb8f..ca3896e2da 100644 --- a/lib/std/log.zig +++ b/lib/std/log.zig @@ -137,8 +137,11 @@ pub fn defaultLogEnabled(comptime message_level: Level) bool { return comptime logEnabled(message_level, default_log_scope); } -/// The default implementation for the log function, custom log functions may +/// The default implementation for the log function. Custom log functions may /// forward log messages to this function. +/// +/// Uses a 64-byte buffer for formatted printing which is flushed before this +/// function returns. pub fn defaultLog( comptime message_level: Level, comptime scope: @Type(.enum_literal), @@ -147,16 +150,10 @@ pub fn defaultLog( ) void { const level_txt = comptime message_level.asText(); const prefix2 = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): "; - const stderr = std.fs.File.stderr().deprecatedWriter(); - var bw = std.io.bufferedWriter(stderr); - const writer = bw.writer(); - - std.debug.lockStdErr(); - defer std.debug.unlockStdErr(); - nosuspend { - writer.print(level_txt ++ prefix2 ++ format ++ "\n", args) catch return; - bw.flush() catch return; - } + var buffer: [64]u8 = undefined; + const stderr = std.debug.lockStderrWriter(&buffer); + defer std.debug.unlockStderrWriter(); + nosuspend stderr.print(level_txt ++ prefix2 ++ format ++ "\n", args) catch return; } /// Returns a scoped logging namespace that logs all messages using the scope |
