pub struct LineSink { /* private fields */ }Expand description
A rotating file sink for bytes the caller has already framed as complete lines — captured child output, forwarded worker rings, anything that is already a log line and must not be re-formatted.
The tracing layer is process-global by construction: one init per process,
one destination. A supervisor needs one rotating file PER CHILD, and those
bytes must reach the child’s own file unchanged rather than becoming events
in the supervisor’s log. Without this type the only options are duplicating
the rotation code (which then drifts from the crate that owns the policy) or
shipping unrotated files (which is how a log reaches 936 MB unnoticed).
The caller owns framing: write_line appends a single trailing newline if
the bytes do not already end with one, and writes exactly once so two pipes
feeding one sink cannot interleave a partial line. Rotation and pruning are
the same policy the layer uses, because it is the same code.
Implementations§
Source§impl LineSink
impl LineSink
Sourcepub fn open(path: &Path, retention: Retention) -> Result<Self>
pub fn open(path: &Path, retention: Retention) -> Result<Self>
Opens (or creates) path with retention, pruning aged generations the
way the layer’s own sink does on open.
Sourcepub fn open_at(
path: &Path,
retention: Retention,
now: SystemTime,
) -> Result<Self>
pub fn open_at( path: &Path, retention: Retention, now: SystemTime, ) -> Result<Self>
open with an explicit clock, so a caller can test rotation and age
pruning without sleeping.
Sourcepub fn write_line(&mut self, line: &[u8]) -> Result<()>
pub fn write_line(&mut self, line: &[u8]) -> Result<()>
Writes one complete line, rotating first if it would exceed the cap.
Sourcepub fn write_line_at(&mut self, line: &[u8], now: SystemTime) -> Result<()>
pub fn write_line_at(&mut self, line: &[u8], now: SystemTime) -> Result<()>
write_line with an explicit clock.