Skip to content

Commit 2b9351a

Browse files
author
Jay
committed
Log to terminal only in debug mode
1 parent 5391999 commit 2b9351a

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.{
22
.name = .engine,
3-
.version = "0.2.2",
3+
.version = "0.2.3",
44
.fingerprint = 0xe8a81a8d0aa558d5,
55
.minimum_zig_version = "0.14.1",
66
.dependencies = .{

src/engine.zig

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5056,18 +5056,23 @@ pub fn log_output(
50565056
args: anytype,
50575057
) void {
50585058
const prefix = "[" ++ comptime level ++ "] ";
5059-
if (scope != .term_scope) {
5060-
var buf: [3000]u8 = undefined;
5061-
if (std.fmt.bufPrintZ(&buf, prefix ++ format, args)) |f| {
5062-
sdl.SDL_LogInfo(@intFromEnum(SdlLogCategory.application), f.ptr);
5063-
} else |_| {
5064-
sdl.SDL_LogInfo(@intFromEnum(SdlLogCategory.application), prefix ++ format);
5065-
}
5066-
}
5067-
std.debug.lockStdErr();
5068-
defer std.debug.unlockStdErr();
5069-
const stderr = std.io.getStdErr().writer();
5070-
nosuspend stderr.print(prefix ++ format ++ "\n", args) catch return;
5059+
if (builtin.mode == .Debug) {
5060+
// Log to terminal in debug mode
5061+
std.debug.lockStdErr();
5062+
defer std.debug.unlockStdErr();
5063+
const stderr = std.io.getStdErr().writer();
5064+
nosuspend stderr.print(prefix ++ format ++ "\n", args) catch return;
5065+
} else {
5066+
// Log using SDL when in release mode
5067+
if (scope != .term_scope) {
5068+
var buf: [3000]u8 = undefined;
5069+
if (std.fmt.bufPrintZ(&buf, prefix ++ format, args)) |f| {
5070+
sdl.SDL_LogInfo(@intFromEnum(SdlLogCategory.application), f.ptr);
5071+
} else |_| {
5072+
sdl.SDL_LogInfo(@intFromEnum(SdlLogCategory.application), prefix ++ format);
5073+
}
5074+
}
5075+
}
50715076
}
50725077

50735078
pub fn log_output_handler(

0 commit comments

Comments
 (0)