Skip to content
FutureBlitz

    Install

    Import std.log.files

    FileSink

    std.log.files

    function

    Public Function FileSink(path: Path): Sendable Func(LogRecord)

    A sink that adds each line, as LogLine has it, with its time and without colors, and a "\n", to the end of the file at path, made, with the folders it's in, when it isn't there; a relative path is from the folder that's current when the sink's made. Each line goes in one write, which no other line's comes into, from this program's threads or, on every OS, another program's adding to the file too. A line that can't be written is gone, and the first of those since one was written says so on stderr.

    Examples

    Local folder = Try TempDir()
    Local output = LogOutput(LogFilter.At(LogLevel.INFO))
    output.Add(FileSink(folder.Path / "app.log"))
    Logger("app", output).Warn("low on disk")
    Expect((Try File.ReadText(folder.Path / "app.log")).Contains("app: low on disk"))
    Try folder.Close()

    std/log/files.fb, line 32

    Report an issue with this page or with FutureBlitz on GitHub.