Import std.log.files
RotatingFileSink
function
@PanicsAtCaller Public Function RotatingFileSink(path: Path, maxBytes: Int64, keep: Int = 5): Sendable Func(LogRecord)
A sink that adds lines as FileSink does, until a line would make the file hold more than
maxBytes: then the file becomes path with ".1" after it, the ".1" before it ".2", and so on,
the oldest of keep going, and the line starts a new file. A file holds one line at least, so
one longer than maxBytes has one of its own. While the file can't be moved aside, which stderr
is told once, lines go on being added to it. Panics when maxBytes isn't above 0, or keep is
below 0; with a keep of 0, the old lines go.
Examples
Local folder = Try TempDir()
Local output = LogOutput(LogFilter.At(LogLevel.INFO))
// Up to 1 MB in app.log, then app.log.1, app.log.2, and app.log.3 for the older lines.
output.Add(RotatingFileSink(folder.Path / "app.log", 1_000_000, 3))
Logger("app", output).Info("started")
Expect((Try File.ReadText(folder.Path / "app.log")).Contains("app: started"))
Try folder.Close()Report an issue with this page or with FutureBlitz on GitHub.