diff options
| author | Isaac Freund <mail@isaacfreund.com> | 2021-10-24 13:13:06 +0200 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-10-24 15:04:29 -0400 |
| commit | f7b090d7076a20a614bf20cac05e5e18c06ad18a (patch) | |
| tree | 72bb252c5352e48ea6d60914debdf5ccc1821dff /src | |
| parent | 6cf5305e47dd8382508f867b04067be615448b41 (diff) | |
| download | zig-f7b090d7076a20a614bf20cac05e5e18c06ad18a.tar.gz zig-f7b090d7076a20a614bf20cac05e5e18c06ad18a.zip | |
std.log: simplify to 4 distinct log levels
Over the last year of using std.log in practice, it has become clear to
me that having the current 8 distinct log levels does more harm than
good. It is too subjective which level a given message should have which
makes filtering based on log level weaker as not all messages will have
been assigned the log level one might expect.
Instead, more granular filtering should be achieved by leveraging the
logging scope feature. Filtering based on a combination of scope and log
level should be sufficiently powerful for all use-cases.
Note that the self hosted compiler has already limited itself to 4
distinct log levels for many months and implemented granular filtering
based on both log scope and level. This has worked very well in practice
while working on the self hosted compiler.
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.zig | 13 |
1 files changed, 3 insertions, 10 deletions
diff --git a/src/main.zig b/src/main.zig index 3fc2be7e30..61380303e1 100644 --- a/src/main.zig +++ b/src/main.zig @@ -27,7 +27,7 @@ const crash_report = @import("crash_report.zig"); pub usingnamespace crash_report.root_decls; pub fn fatal(comptime format: []const u8, args: anytype) noreturn { - std.log.emerg(format, args); + std.log.err(format, args); process.exit(1); } @@ -94,7 +94,7 @@ const usage = if (debug_extensions_enabled) debug_usage else normal_usage; pub const log_level: std.log.Level = switch (builtin.mode) { .Debug => .debug, .ReleaseSafe, .ReleaseFast => .info, - .ReleaseSmall => .crit, + .ReleaseSmall => .err, }; var log_scopes: std.ArrayListUnmanaged([]const u8) = .{}; @@ -120,14 +120,7 @@ pub fn log( } else return; } - // We only recognize 4 log levels in this application. - const level_txt = switch (level) { - .emerg, .alert, .crit, .err => "error", - .warn => "warning", - .notice, .info => "info", - .debug => "debug", - }; - const prefix1 = level_txt; + const prefix1 = comptime level.asText(); const prefix2 = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): "; // Print the message to stderr, silently ignoring any errors |
