From 495d18a2056882d7edc7376751e7f3d4e10ef920 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 25 Sep 2020 00:00:04 -0700 Subject: 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. --- lib/std/log.zig | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'lib/std/log.zig') diff --git a/lib/std/log.zig b/lib/std/log.zig index 7b677f698a..bc83e6053d 100644 --- 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; } } } -- cgit v1.2.3