i rewrote logging in my app to use std.log, scoped on various files
in main.zig, I have something like
pub const std_options: std.Options = .{
// .log_level = std.log.Level.info,
.log_scope_levels = &[_]std.log.ScopeLevel{
.{ .scope = .gb, .level = .info },
.{ .scope = .cpu, .level = .debug },
.{ .scope = .gpu, .level = .info },
.{ .scope = .mbc, .level = .info },
.{ .scope = .timer, .level = .info },
.{ .scope = .joy, .level = .info },
.{ .scope = .bus, .level = .info },
},
};
cpu is at debug, as i want to test something specific to it
in cpu.zig,
const log = std.log.scoped(.cpu);
with a function
fn beeg_print(self: *CPU) void {
// if (self.pc <= 0x100) {
// return;
// }
log.debug(“A: {X:0>2} F: {X:0>2} B: {X:0>2} C: {X:0>2} D: {X:0>2} E: {X:0>2} H: {X:0>2} L: {X:0>2} SP: {X:0>4} PC: 00:{X:0>4} ({X:0>2} {X:0>2} {X:0>2} {X:0>2})\n”, .{
self.registers.A,
@as(u8, @bitCast(self.registers.F)),
self.registers.B,
self.registers.C,
self.registers.D,
self.registers.E,
self.registers.H,
self.registers.L,
self.sp,
self.pc,
self.bus.read_byte(self.pc),
self.bus.read_byte(self.pc +% 1),
self.bus.read_byte(self.pc +% 2),
self.bus.read_byte(self.pc +% 3),
});
The code is single threaded and I use the function once per loop. I’m tracing cpu emulator output, so it’s printing a lot. I’ve tested switching between a bufferedwriter written myself and std.log and observe double printing when using std.log. from reading source, stdlog uses bufferedwriter with little else added. any idea what im missing?