zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 495d18a2056882d7edc7376751e7f3d4e10ef920 (tree)
parent 30dfdfdbd09570f97420413015eb8a1517382961
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Fri, 25 Sep 2020 00:00:04 -0700

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.

Diffstat:
Mlib/std/log.zig | 15+++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/lib/std/log.zig b/lib/std/log.zig @@ -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; } } }