authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-11-19 18:53:37 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-11-19 18:53:37 -08:00
log39a43e1bacabb514e6479795899b097022789623
tree747c3286703f62608e206085bf91029c45c7106b
parenta715c0c693801013e99801c92f7500d2fcb97229

allow passing a fmt+args to trace()


5 files changed, 12 insertions(+), 10 deletions(-)

src/log.zig+2-2
......@@ -10,8 +10,8 @@ pub fn init_thread() !void {}
1010
1111pub fn deinit_thread() void {}
1212
13pub inline fn trace_begin(ctx: tracer.Ctx) void {
14 log.debug("{s}:{d}:{d} ({s})", .{ ctx.src.file, ctx.src.line, ctx.src.column, ctx.src.fn_name });
13pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: anytype) void {
14 log.debug("{s}:{d}:{d} ({s})" ++ ifmt, .{ ctx.src.file, ctx.src.line, ctx.src.column, ctx.src.fn_name } ++ iargs);
1515}
1616
1717pub inline fn trace_end(ctx: tracer.Ctx) void {
src/main.zig+1-1
......@@ -24,6 +24,6 @@ pub fn main() !void {
2424}
2525
2626fn handler() void {
27 const t = tracer.trace(@src());
27 const t = tracer.trace(@src(), "", .{});
2828 defer t.end();
2929}
src/mod.zig+2-2
......@@ -26,11 +26,11 @@ pub fn deinit_thread() void {
2626 impl.deinit_thread();
2727}
2828
29pub inline fn trace(src: std.builtin.SourceLocation) Ctx {
29pub inline fn trace(src: std.builtin.SourceLocation, comptime fmt: []const u8, args: anytype) Ctx {
3030 const ctx = Ctx{
3131 .src = src,
3232 };
33 if (started) impl.trace_begin(ctx);
33 if (started) impl.trace_begin(ctx, fmt, args);
3434 return ctx;
3535}
3636
src/none.zig+3-1
......@@ -10,8 +10,10 @@ pub fn init_thread() !void {}
1010
1111pub fn deinit_thread() void {}
1212
13pub inline fn trace_begin(ctx: tracer.Ctx) void {
13pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: anytype) void {
1414 _ = ctx;
15 _ = ifmt;
16 _ = iargs;
1517}
1618
1719pub inline fn trace_end(ctx: tracer.Ctx) void {
src/spall.zig+4-4
......@@ -37,8 +37,8 @@ pub fn deinit_thread() void {
3737 log.debug("{s}", .{path});
3838}
3939
40pub inline fn trace_begin(ctx: tracer.Ctx) void {
41 const fmt = "{s}:{d}:{d} ({s})";
40pub inline fn trace_begin(ctx: tracer.Ctx, comptime ifmt: []const u8, iargs: anytype) void {
41 const fmt = "{s}:{d}:{d} ({s})" ++ ifmt;
4242 const args = .{
4343 if (ctx.src.file[0] == '/') ctx.src.file[trim_count..] else ctx.src.file,
4444 ctx.src.line,
......@@ -49,10 +49,10 @@ pub inline fn trace_begin(ctx: tracer.Ctx) void {
4949 .pid = @intCast(pid),
5050 .tid = @intCast(tid),
5151 .time = @floatFromInt(std.time.microTimestamp()),
52 .name_len = @intCast(std.fmt.count(fmt, args)),
52 .name_len = @intCast(std.fmt.count(fmt, args ++ iargs)),
5353 .args_len = 0,
5454 }) catch return;
55 buffered_writer.writer().print(fmt, args) catch return;
55 buffered_writer.writer().print(fmt, args ++ iargs) catch return;
5656}
5757
5858pub inline fn trace_end(ctx: tracer.Ctx) void {