std.log.defaultLog: provide a small buffer
This commit is contained in:
@@ -137,8 +137,11 @@ pub fn defaultLogEnabled(comptime message_level: Level) bool {
|
|||||||
return comptime logEnabled(message_level, default_log_scope);
|
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.
|
/// forward log messages to this function.
|
||||||
|
///
|
||||||
|
/// Uses a 64-byte buffer for formatted printing which is flushed before this
|
||||||
|
/// function returns.
|
||||||
pub fn defaultLog(
|
pub fn defaultLog(
|
||||||
comptime message_level: Level,
|
comptime message_level: Level,
|
||||||
comptime scope: @Type(.enum_literal),
|
comptime scope: @Type(.enum_literal),
|
||||||
@@ -147,16 +150,10 @@ pub fn defaultLog(
|
|||||||
) void {
|
) void {
|
||||||
const level_txt = comptime message_level.asText();
|
const level_txt = comptime message_level.asText();
|
||||||
const prefix2 = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): ";
|
const prefix2 = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): ";
|
||||||
const stderr = std.fs.File.stderr().deprecatedWriter();
|
var buffer: [64]u8 = undefined;
|
||||||
var bw = std.io.bufferedWriter(stderr);
|
const stderr = std.debug.lockStderrWriter(&buffer);
|
||||||
const writer = bw.writer();
|
defer std.debug.unlockStderrWriter();
|
||||||
|
nosuspend stderr.print(level_txt ++ prefix2 ++ format ++ "\n", args) catch return;
|
||||||
std.debug.lockStdErr();
|
|
||||||
defer std.debug.unlockStdErr();
|
|
||||||
nosuspend {
|
|
||||||
writer.print(level_txt ++ prefix2 ++ format ++ "\n", args) catch return;
|
|
||||||
bw.flush() catch return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a scoped logging namespace that logs all messages using the scope
|
/// Returns a scoped logging namespace that logs all messages using the scope
|
||||||
|
|||||||
Reference in New Issue
Block a user