Skip to content
FutureBlitz

    Install

    Import std.log.logger

    Logger

    std.log.logger

    class

    Public Shared Class Logger

    Writes lines for a module, with the fields it's given, at levels, to an output. Its Trace, Debug, Info, Warn, and Error write a line at their level, when the output's filter writes that level for the module.

    Examples

    Const lines = Channel<String>(8)
    
    Function Keep(line: String)
        lines.Send(line)
    End Function
    
    Local output = LogOutput(LogFilter.At(LogLevel.INFO))
    output.Add(JsonLinesSink(Keep))
    Local log = Logger("shop", output).With("user", "ada")
    log.Debug("not written, as DEBUG is below INFO")
    log.Info("signed in")
    Local line = lines.TryReceive() ?? ""
    Expect(line.Contains("\"message\":\"signed in\"") && line.Contains("\"user\":\"ada\""))
    Expect(lines.TryReceive() == Null)

    std/log/logger.fb, line 75

    • Public New(module: String) constructor #

      A Logger for module, a name like "net.http" whose dots say what it's in, which writes to the default output.

    • Public New(module: String, output: LogOutput) constructor #

      A Logger for module that writes to output.

    • Public Property Module: String property #

      The module it writes for.

    • Public Property Fields: ImmutableArray<LogField> property #

      The fields each of its lines has, in the order they were given.

    • Public Method With(name: String, value: String): Logger method #

      A Logger like this one whose lines have the field too, after its others.

    • Public Method With(name: String, value: Int8): Logger method #

      A Logger whose lines have the field name, of value's number, beside this one's: each of the eight integer types has one.

    • Public Method With(name: String, value: Int16): Logger method #

      A Logger whose lines have the field name, of value's number, beside this one's.

    • Public Method With(name: String, value: Int): Logger method #

      A Logger whose lines have the field name, of value's number, beside this one's.

    • Public Method With(name: String, value: Int64): Logger method #

      A Logger whose lines have the field name, of value's number, beside this one's.

    • Public Method With(name: String, value: UInt8): Logger method #

      A Logger whose lines have the field name, of value's number, beside this one's.

    • Public Method With(name: String, value: UInt16): Logger method #

      A Logger whose lines have the field name, of value's number, beside this one's.

    • Public Method With(name: String, value: UInt32): Logger method #

      A Logger whose lines have the field name, of value's number, beside this one's.

    • Public Method With(name: String, value: UInt64): Logger method #

      A Logger whose lines have the field name, of value's number, beside this one's.

    • Public Method With(name: String, value: Float64): Logger method #

      A Logger whose lines have the field name, of value's number. A Double that isn't finite is text, since JSON has no number for it: "inf", "-inf", or "nan", whatever a NaN's sign bit.

    • Public Method With(name: String, value: Bool): Logger method #

      A Logger whose lines have the field name, true or false, beside this one's.

    • Public Method IsEnabled(level: LogLevel): Bool method #

      Whether a line at level would be written, so code can leave out work that only a line would use.

    • Public Method Log(level: LogLevel, message: String) method #

      Writes message at level, now, when the output's filter writes it.

    • Public Method Trace(message: String) method #

      Writes message at TRACE, as Log does.

    • Public Method Debug(message: String) method #

      Writes message at DEBUG, as Log does.

    • Public Method Info(message: String) method #

      Writes message at INFO, as Log does.

    • Public Method Warn(message: String) method #

      Writes message at WARN, as Log does.

    • Public Method Error(message: String) method #

      Writes message at ERROR, as Log does.

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