| ... | @@ -137,8 +137,11 @@ pub fn defaultLogEnabled(comptime message_level: Level) bool { | ... | @@ -137,8 +137,11 @@ pub fn defaultLogEnabled(comptime message_level: Level) bool { |
| 137 | return comptime logEnabled(message_level, default_log_scope); | 137 | return comptime logEnabled(message_level, default_log_scope); |
| 138 | } | 138 | } |
| 139 | | 139 | |
| 140 | /// The default implementation for the log function, custom log functions may | 140 | /// The default implementation for the log function. Custom log functions may |
| 141 | /// forward log messages to this function. | 141 | /// forward log messages to this function. |
| | 142 | /// |
| | 143 | /// Uses a 64-byte buffer for formatted printing which is flushed before this |
| | 144 | /// function returns. |
| 142 | pub fn defaultLog( | 145 | pub fn defaultLog( |
| 143 | comptime message_level: Level, | 146 | comptime message_level: Level, |
| 144 | comptime scope: @Type(.enum_literal), | 147 | comptime scope: @Type(.enum_literal), |
| ... | @@ -147,16 +150,10 @@ pub fn defaultLog( | ... | @@ -147,16 +150,10 @@ pub fn defaultLog( |
| 147 | ) void { | 150 | ) void { |
| 148 | const level_txt = comptime message_level.asText(); | 151 | const level_txt = comptime message_level.asText(); |
| 149 | const prefix2 = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): "; | 152 | const prefix2 = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): "; |
| 150 | const stderr = std.fs.File.stderr().deprecatedWriter(); | 153 | var buffer: [64]u8 = undefined; |
| 151 | var bw = std.io.bufferedWriter(stderr); | 154 | const stderr = std.debug.lockStderrWriter(&buffer); |
| 152 | const writer = bw.writer(); | 155 | defer std.debug.unlockStderrWriter(); |
| 153 | | 156 | nosuspend stderr.print(level_txt ++ prefix2 ++ format ++ "\n", args) catch return; |
| 154 | std.debug.lockStdErr(); | | |
| 155 | defer std.debug.unlockStdErr(); | | |
| 156 | nosuspend { | | |
| 157 | writer.print(level_txt ++ prefix2 ++ format ++ "\n", args) catch return; | | |
| 158 | bw.flush() catch return; | | |
| 159 | } | | |
| 160 | } | 157 | } |
| 161 | | 158 | |
| 162 | /// Returns a scoped logging namespace that logs all messages using the scope | 159 | /// Returns a scoped logging namespace that logs all messages using the scope |