diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-09-25 00:00:04 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-09-25 00:02:52 -0700 |
| commit | 495d18a2056882d7edc7376751e7f3d4e10ef920 (patch) | |
| tree | 795a98eb0209efebacf0799f07834e5b03372379 /lib/std/log.zig | |
| parent | 30dfdfdbd09570f97420413015eb8a1517382961 (diff) | |
| download | zig-495d18a2056882d7edc7376751e7f3d4e10ef920.tar.gz zig-495d18a2056882d7edc7376751e7f3d4e10ef920.zip | |
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 (limited to 'lib/std/log.zig')
| -rw-r--r-- | lib/std/log.zig | 15 |
1 files changed, 13 insertions, 2 deletions
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; } } } |
