authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-25 00:00:04-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-25 00:02:52-07:00
log495d18a2056882d7edc7376751e7f3d4e10ef920
tree795a98eb0209efebacf0799f07834e5b03372379
parent30dfdfdbd09570f97420413015eb8a1517382961

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.

1 files changed, 13 insertions(+), 2 deletions(-)

lib/std/log.zig+13-2
......@@ -132,10 +132,21 @@ fn log(
132132 // any I/O configured.
133133 return;
134134 } else if (builtin.mode != .ReleaseSmall) {
135 const level_txt = switch (message_level) {
136 .emerg => "emergency",
137 .alert => "alert",
138 .crit => "critical",
139 .err => "error",
140 .warn => "warning",
141 .notice => "notice",
142 .info => "info",
143 .debug => "debug",
144 };
145 const prefix2 = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): ";
146 const stderr = std.io.getStdErr().writer();
135147 const held = std.debug.getStderrMutex().acquire();
136148 defer held.release();
137 const stderr = std.io.getStdErr().writer();
138 nosuspend stderr.print(format ++ "\n", args) catch return;
149 nosuspend stderr.print(level_txt ++ prefix2 ++ format ++ "\n", args) catch return;
139150 }
140151 }
141152}