| ... | @@ -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 | |
| | 592 | pub 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 | } |