authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-07-09 13:42:26 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-07-09 13:42:26 -07:00
logbd01c347af73ff79666d357545b3e821c83fdaf8
treeffe5d3d9c1514722a7cb59b2242d148c8f2fb58d
parenta81515cba8b6d79513f70f5062f1c2e9c416549b

add LoggingWriter


1 files changed, 26 insertions(+), 0 deletions(-)

src/lib.zig+26
...@@ -588,3 +588,29 @@ pub fn LoggingReader(comptime T: type, comptime scope: @Type(.EnumLiteral)) type...@@ -588,3 +588,29 @@ pub fn LoggingReader(comptime T: type, comptime scope: @Type(.EnumLiteral)) type
588 }588 }
589 };589 };
590}590}
591
592pub fn LoggingWriter(comptime T: type, comptime scope: @Type(.EnumLiteral)) type {
593 return struct {
594 child_stream: T,
595
596 pub const Error = T.Error;
597 pub const Writer = std.io.Writer(Self, Error, write);
598
599 const Self = @This();
600
601 pub fn init(child_stream: T) Self {
602 return .{
603 .child_stream = child_stream,
604 };
605 }
606
607 pub fn writer(self: Self) Writer {
608 return .{ .context = self };
609 }
610
611 fn write(self: Self, bytes: []const u8) Error!usize {
612 std.log.scoped(scope).debug("{s}", .{bytes});
613 return self.child_stream.write(bytes);
614 }
615 };
616}