From 2c4ac3819b8c42de1410fd524c2c9d08d937ec70 Mon Sep 17 00:00:00 2001 From: Martin Ashby Date: Sun, 3 Sep 2023 20:32:51 +0100 Subject: Initial --- src/log.zig | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/log.zig (limited to 'src/log.zig') diff --git a/src/log.zig b/src/log.zig new file mode 100644 index 0000000..dd81d5f --- /dev/null +++ b/src/log.zig @@ -0,0 +1,18 @@ +const std = @import("std"); +const builtin = @import("builtin"); +/// Workaround for failing tests when errors are logged +/// https://github.com/ziglang/zig/issues/5738#issuecomment-1466902082 +pub fn scoped_log_t(comptime scope: @Type(.EnumLiteral)) type { + return if (builtin.is_test) + // Downgrade `err` to `warn` for tests. + // Zig fails any test that does `log.err`, but we want to test those code paths here. + struct { + pub const base = std.log.scoped(scope); + pub const err = warn; + pub const warn = base.warn; + pub const info = base.info; + pub const debug = base.debug; + } + else + std.log.scoped(scope); +} -- cgit v1.2.3-ZIG