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:
Andrew Kelley 2020-09-25 00:00:04 -07:00
parent 30dfdfdbd0
commit 495d18a205

View File

@ -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;
}
}
}