@std/log.ms#
Import each required symbol with import Name from "@std/log.ms".
LogError Alternative#
Errors returned while validating or writing a structured log record.
type LogError:
case InvalidInput
case InvalidData
case LimitExceeded
case Closed
case Io(cause: IoError)
case FileSystem(cause: FileSystemError)impl Error for LogError:
fn message() -> String:LogError.Closed#
The native transport has closed, so an admitted write or flush cannot complete.
case ClosedLogError.FileSystem#
Opening the owned file transport returned a filesystem error.
case FileSystem(cause: FileSystemError)LogError.InvalidData#
Structured fields cannot be encoded as valid JSON, including cyclic values.
case InvalidDataLogError.InvalidInput#
The selected record level or an explicit record-size budget is invalid.
case InvalidInputLogError.Io#
A transport’s underlying byte-stream operation returned its original I/O error.
case Io(cause: IoError)LogError.LimitExceeded#
The JSON record plus its terminating newline exceeds the supplied byte budget.
case LimitExceededLogError.FileSystem.cause#
Original filesystem error retained from file acquisition.
cause: FileSystemErrorLogError.Io.cause#
Original stream error; its message and concrete case are preserved.
cause: IoErrorLogError.Error.message#
Returns the preserved I/O/filesystem cause message, or a logging-prefixed diagnostic.
fn message() -> String:LogLevel Alternative#
Severity levels accepted by a logger, ordered from Trace through Fatal.
type LogLevel:
case Trace
case Debug
case Info
case Warn
case Error
case Fatal
case SilentLogLevel.Debug#
Development diagnostics, encoded with numeric level 20.
case DebugLogLevel.Error#
Failure records, encoded with numeric level 50.
case ErrorLogLevel.Fatal#
Critical records at numeric level 60; logging does not terminate the process.
case FatalLogLevel.Info#
Ordinary operational records, encoded with numeric level 30; the default threshold.
case InfoLogLevel.Silent#
Filtering threshold that disables records; passing it to log returns InvalidInput.
case SilentLogLevel.Trace#
Most detailed records, encoded with numeric level 10.
case TraceLogLevel.Warn#
Warning records, encoded with numeric level 40.
case WarnLogger Interface#
A structured logger with level filtering, bound fields, and pluggable transports.
interface Logger:
fn log(level: LogLevel, message: String, fields: Optional[Map[String, JsonValue]] = none) -> Result[Unit, LogError]
fn trace(message: String, fields: Optional[Map[String, JsonValue]] = none) -> Result[Unit, LogError]
fn debug(message: String, fields: Optional[Map[String, JsonValue]] = none) -> Result[Unit, LogError]
fn info(message: String, fields: Optional[Map[String, JsonValue]] = none) -> Result[Unit, LogError]
fn warn(message: String, fields: Optional[Map[String, JsonValue]] = none) -> Result[Unit, LogError]
fn error(message: String, fields: Optional[Map[String, JsonValue]] = none) -> Result[Unit, LogError]
fn fatal(message: String, fields: Optional[Map[String, JsonValue]] = none) -> Result[Unit, LogError]
fn enabled(level: LogLevel) -> Bool
fn level() -> LogLevel
fn set_level(level: LogLevel) -> Unit
fn child(bindings: Map[String, JsonValue]) -> Logger
fn flush() -> Result[Unit, LogError]Logger.child#
Returns a logger that adds these fields to each record.
fn child(bindings: Map[String, JsonValue]) -> LoggerLogger.debug#
Logs at Debug when enabled, with call fields overriding child bindings for duplicate keys.
fn debug(message: String, fields: Optional[Map[String, JsonValue]] = none) -> Result[Unit, LogError]Logger.enabled#
Tests the current filtering threshold; Silent is never enabled as a record level.
fn enabled(level: LogLevel) -> BoolLogger.error#
Logs at Error when enabled; it records an expected diagnostic rather than raising a fault.
fn error(message: String, fields: Optional[Map[String, JsonValue]] = none) -> Result[Unit, LogError]Logger.fatal#
Logs at Fatal when enabled; the caller remains responsible for process termination.
fn fatal(message: String, fields: Optional[Map[String, JsonValue]] = none) -> Result[Unit, LogError]Logger.flush#
Flushes the logger’s transport.
fn flush() -> Result[Unit, LogError]Logger.info#
Logs at Info when enabled; reserved level, msg, and time fields remain controlled by the logger.
fn info(message: String, fields: Optional[Map[String, JsonValue]] = none) -> Result[Unit, LogError]Logger.level#
Returns this logger’s current threshold, independent of its parent or children.
fn level() -> LogLevelLogger.log#
Writes a record at the selected level with optional JSON fields.
fn log(level: LogLevel, message: String, fields: Optional[Map[String, JsonValue]] = none) -> Result[Unit, LogError]Logger.set_level#
Changes only this logger’s threshold; existing child loggers retain their copied threshold.
fn set_level(level: LogLevel) -> UnitLogger.trace#
Logs at Trace when enabled; a filtered call returns ok without encoding or transport access.
fn trace(message: String, fields: Optional[Map[String, JsonValue]] = none) -> Result[Unit, LogError]Logger.warn#
Logs at Warn when enabled, returning encoding, size-budget, or transport errors unchanged.
fn warn(message: String, fields: Optional[Map[String, JsonValue]] = none) -> Result[Unit, LogError]Transport Interface#
A destination that accepts encoded log records and can be flushed and closed.
interface Transport:
fn write(data: Bytes) -> Result[Unit, LogError]
fn flush() -> Result[Unit, LogError]
fn close() -> UnitTransport.close#
Releases owned resources; native close cancels admitted operations and leaves borrowed streams open.
fn close() -> UnitTransport.flush#
Delegates flush to the destination; persistence and buffering depend on that destination.
fn flush() -> Result[Unit, LogError]Transport.write#
Accepts encoded record bytes; native transports serialize writes and may return the original I/O cause. Errors can follow a partial external write, without rollback.
fn write(data: Bytes) -> Result[Unit, LogError]create Function#
Creates a logger. Defaults to Info, no bound fields, timestamps enabled, and no record-size limit.
fn create(transport: Transport, level: Optional[LogLevel] = none, bindings: Optional[Map[String, JsonValue]] = none, timestamp: Optional[Bool] = none, max_bytes: Optional[Int] = none) -> Result[Logger, LogError]:file_transport Function#
Appends log records to a file at path.
fn file_transport(path: String) -> Result[Transport, LogError]:stdout_transport Function#
Writes log records to the process standard-output stream.
fn stdout_transport() -> Transport:stream_transport Function#
Writes log records to an existing byte stream.
fn stream_transport(output: WriteStream) -> Transport: