mirror of
https://github.com/ziglang/zig.git
synced 2025-02-14 16:40:17 +00:00
std.log: better default for printing logs
* prefix with the message level * if the scope is not default, also prefix with the scope This makes the stack trace test pass, with no changes to the test case, because errors returned from main() now print `error: Foo` just like they do in master branch.
This commit is contained in:
parent
30dfdfdbd0
commit
495d18a205
@ -132,10 +132,21 @@ fn log(
|
||||
// any I/O configured.
|
||||
return;
|
||||
} else if (builtin.mode != .ReleaseSmall) {
|
||||
const level_txt = switch (message_level) {
|
||||
.emerg => "emergency",
|
||||
.alert => "alert",
|
||||
.crit => "critical",
|
||||
.err => "error",
|
||||
.warn => "warning",
|
||||
.notice => "notice",
|
||||
.info => "info",
|
||||
.debug => "debug",
|
||||
};
|
||||
const prefix2 = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): ";
|
||||
const stderr = std.io.getStdErr().writer();
|
||||
const held = std.debug.getStderrMutex().acquire();
|
||||
defer held.release();
|
||||
const stderr = std.io.getStdErr().writer();
|
||||
nosuspend stderr.print(format ++ "\n", args) catch return;
|
||||
nosuspend stderr.print(level_txt ++ prefix2 ++ format ++ "\n", args) catch return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user